significant-rounding
function(number
, minTotalLength=9 //Including comma
, minDecimals=2 //How many decimals when number has no decimal places
, trailingZeros = false //Trailing zeros when abs(number) is less than 1
, significantRounding=null)
If absolute number is greater than zero (num > 0) then minDecimals and normal formatting is used.
rounding(123.123456, 5); //Outputs 123.12
rounding(123.100000, 5); //Outputs 123.10
rounding(123.100000, 5, 4, true); //Outputs 123.1000
rounding(1234.12, 2, 2, true, 3)); //Outputs 1230.00
If absolute number is less than zero (num < 0) then maxDecimals and significant rounding is used.
rounding(0.0000123456789, 5); //Outputs 0.000012346
rounding(0.0123456789, 5); //Outputs 0.012346
rounding(0.012, 5); //Outputs 0.012
rounding(0.012, 5, true); //Outputs 0.012000
rounding(0.0123001, 5); //Outputs 0.01230