locutusjs / locutus

Bringing stdlibs of other programming languages to JavaScript for educational purposes

Home Page:https://locutus.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

round(4096.485, 2) => 4096.48

morskoyzmey opened this issue · comments

It's a magic border.
Although some bigger numbers works right too. For example 14096.485

The problem:

> console.log(4096.485 * 100)
409648.49999999994

One solution could be to use epsilon in the comparison:

isHalf = value % 1 === 0.5 * sgn

http://stackoverflow.com/questions/5037839/avoiding-problems-with-javascripts-weird-decimal-calculations

This is now fixed. It turned out that PHP performs an additional rounding to some specific precision before rounding to the precision the function caller expects.
The aim is to deliver “human-understandable” results despite FP specifics/limitations.
I’m closing the ticket.