You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
1.3 KiB
44 lines
1.3 KiB
extension IntExt on int {
|
|
String get formatRank {
|
|
if (this < 1000) {
|
|
return toString();
|
|
} else if (this < 1000000) {
|
|
return '${_formatResult((this / 1000))}K';
|
|
} else if (this < 1000000000) {
|
|
return '${_formatResult(this / 1000000)}M';
|
|
}
|
|
return '${_formatResult(this / 1000000000)}B';
|
|
}
|
|
|
|
String get formatUSDString {
|
|
return (this / 100).toStringAsFixed(2);
|
|
}
|
|
|
|
String _formatResult(double value) {
|
|
value.toStringAsFixed(2);
|
|
final String resultStr = value.toString(); //value.toStringAsFixed(2);
|
|
final index = resultStr.lastIndexOf('.') + 3;
|
|
String resultVlueStr = resultStr;
|
|
if (index < resultStr.length) {
|
|
resultVlueStr = resultStr.substring(0, index);
|
|
}
|
|
return resultVlueStr.endsWith('.0')
|
|
? value.toStringAsFixed(0)
|
|
: resultVlueStr;
|
|
}
|
|
|
|
String get formatDurationFromSeconds{
|
|
Duration duration = Duration(seconds: this);
|
|
String twoDigits(int n) => n.toString().padLeft(2, '0');
|
|
String minutes = twoDigits(duration.inMinutes.remainder(60));
|
|
String seconds = twoDigits(duration.inSeconds.remainder(60));
|
|
|
|
if (duration.inHours > 0) {
|
|
String hours = duration.inHours.toString();
|
|
return "$hours:$minutes:$seconds";
|
|
} else {
|
|
return "$minutes:$seconds";
|
|
}
|
|
}
|
|
|
|
}
|