Skip to content

Commit

Permalink
[Utils] Update function formatValue to return grouped number
Browse files Browse the repository at this point in the history
  • Loading branch information
Sam1kumar authored and TusharFA committed Jan 12, 2023
1 parent 36453e4 commit de445c4
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/src/utils/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,12 @@ bool isListEmpty(List? value) => !checkIfListIsNotEmpty(value);
/// 32421.32 will be returned as 32.42K
/// 324936.21 will be returned as 3.25L
String formatValue(double value,
{int decimalPlaces = 0, String locale = 'en_IN'}) {
{int decimalPlaces = 0, String locale = 'en_IN', bool isCompact = true}) {
if (locale == 'en_IN') {
if (!isCompact) {
final formatter = NumberFormat("##,##,###.0#");
return formatter.format(value);
}
if (value > 10000000) {
final calculated = value / 10000000;
return '${calculated.toStringAsFixed(decimalPlaces)}Cr';
Expand All @@ -40,6 +44,10 @@ String formatValue(double value,
return value.toStringAsFixed(decimalPlaces);
}
} else {
if (!isCompact) {
final formatter = NumberFormat("###,###.0#");
return formatter.format(value);
}
if (value > 1000000000) {
final calculated = value / 1000000000;
return '${calculated.toStringAsFixed(decimalPlaces)}B';
Expand Down

0 comments on commit de445c4

Please sign in to comment.