NumericUtil
NumericUtil
class provides utility methods for numerical operations.
Methods
round(value: Double, places: Integer): Double
Rounds a number to the specified number of decimal places using the default rounding mode (HALF_UP).
var value = 3.14159;
var roundedValue = NumericUtil.round(value, 2);
return roundedValue; // Output: 3.14
roundUp(value: Double, places: Integer): Double
Rounds a number up to the specified number of decimal places, always rounding up to the nearest value.
var value = 3.14159;
var roundedValue = NumericUtil.roundUp(value, 2);
return roundedValue; // Output: 3.14
roundDown(value: Double, places: Integer): Double
Rounds a number down to the specified number of decimal places, always rounding down to the nearest value.
var value = 3.14159;
var roundedValue = NumericUtil.roundDown(value, 2);
return roundedValue; // Output: 3.14
parseCustomDouble(value: String, decimalSeparator: String, thousandSeparator: String): Double
Parses a string as a double value.
var value = "1,000.5"
var customDecimalSeparator = '.';
var customThousandSeparator = ',';
NumericUtil.parseCustomDouble(value, customDecimalSeparator, customThousandSeparator);
formatCustomDouble(value: Double, decimalSeparator: String, thousandSeparator: String): Double
Formats a double value as a string.
var value = 1000.5
var customDecimalSeparator = '.';
var customThousandSeparator = ',';
NumericUtil.formatCustomDouble(value, customDecimalSeparator, customThousandSeparator);
Last updated