Task: Add format number with precision and updated for dart shared
This commit is contained in:
@@ -32,4 +32,8 @@ extension StringExtensionOnNullable on String? {
|
||||
bool get isNullOrEmptyOrBlank => StringUtils.isNullOrEmptyOrBlank(this);
|
||||
|
||||
bool get isEqualsIgnoreCase => StringUtils.equalsIgnoreCase(this, this);
|
||||
|
||||
String toPrecision([int precision = 2]) {
|
||||
return StringUtils.formatFromString(this, precision);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,13 @@ class StringUtils {
|
||||
return n.toStringAsFixed(n.truncateToDouble() == n ? precision : precision);
|
||||
}
|
||||
|
||||
/// Format number from String with precision
|
||||
static String formatFromString(String? text, [int precision = 2]) {
|
||||
text ??= '0.0';
|
||||
var n = double.parse(text);
|
||||
return n.toStringAsFixed(n.truncateToDouble() == n ? precision : precision);
|
||||
}
|
||||
|
||||
/// Text format with custom args
|
||||
static String? textFormat(String? text, List<dynamic> args) =>
|
||||
TextFormatter(text).format(args);
|
||||
|
||||
Reference in New Issue
Block a user