numbro icon indicating copy to clipboard operation
numbro copied to clipboard

Floating point bug in percent formatting

Open NikkiMeganMoore opened this issue 5 years ago • 4 comments

Formatting a percent value with format string "0%" (no decimals) doesn't work properly

Examples: numbro(0.811).format('0%') => "81.10000000000001%" numbro(1.1).format('0%') => "110.00000000000001%" numbro(1.15)format('0%) => "114.99999999999999%" numbro(5.1).format('0%') => "509.99999999999994%" numbro(9.8).format('0%') => "980.0000000000001%"

This is numbro version 2.2.0

NikkiMeganMoore avatar May 13 '20 20:05 NikkiMeganMoore

I'm getting the same issue as well with the latest version 2.3.1.

numbro(83.5458).format('0%');
numbro(83.5458).format({output: "percent"});
// 8354.58%

kawanuaid avatar Jul 17 '20 10:07 kawanuaid

Seeing this here too (2.3.2). Any updates?

Moorst avatar Jan 04 '21 16:01 Moorst

Do you guys have any updates regarding this issue?

pasindu-pr avatar Jun 14 '22 12:06 pasindu-pr

Setting mantissa to 0 works to me.

numbro(1.1).format({output: "percent", mantissa: 0});

Kramy avatar Mar 17 '23 13:03 Kramy