Skip to content

Instantly share code, notes, and snippets.

@Laebrye
Created August 2, 2023 11:15
Show Gist options
  • Save Laebrye/07a806065e11a32a2e61eb7675157fbd to your computer and use it in GitHub Desktop.
Save Laebrye/07a806065e11a32a2e61eb7675157fbd to your computer and use it in GitHub Desktop.
jade-crest-7634
void main() {
print(integralPart(2499,2));
print(fractionalPart(2499,2));
}
String? integralPart(int? centAmount, int? fractionDigits) {
final cent = ((centAmount?.toString().length ?? 0) - (fractionDigits ?? 0));
return centAmount?.toString().substring(0, cent >= 0 ? cent : null);
}
String? fractionalPart(int? centAmount, int? fractionDigits) {
final cent = ((centAmount?.toString().length ?? 0) - (fractionDigits ?? 0));
return centAmount?.toString().substring(cent >= 0 ? cent : 0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment