Hello, friends) I have a problem. In the case when I’m using numeric render I have some gap with rounding number in the cell. This issue more related to numbro.js, that Handsontable use for numeric renders: for example, I can type or get calculation result from the server in form 999999,999999788. Now it will round to 1000000,000000, and it’s wrong according to my business logic because I can have such numbers. All my validators are depended on the numeric renderer. How can I solve this issue, using custom renderer?
Issue with wrong numbers rounding using numeric renderer(numro.js most likely)
Hi @samteammail
I have already replied to your email with the same question. So I just paste the content for all other users that may look for a similar topic
'I have tried this example http://jsfiddle.net/handsoncode/a2fbwmbd/ with 10 decimal places in format attribute and this demo with 11 places http://jsfiddle.net/handsoncode/qd5rt1y1/ that serves even more odd results.
One of our users wrote this library can be handy while using large decimals https://mikemcl.github.io/big.js/ but I did not use it personally.’
The subject is under investigation. However, I am not sure how much we can do without Numbro’s input.
Yes, thank you. I would like to clarify my request - it works good for edit, but after you’re finishing it, the number will round. Try to put even in your example - 999999.9999999999. In view, you’ll see 1,000,000.000000000. Same for - 999999.9999999978 -> 999,999.999999998. It’s not correct for my business logic - I want to see the same value)
p.s. As you can see, in edit mode it works right., that’s why there is no sense to use some extra libraries Maybe it makes sense to add some property to the renderer for view mode?
Back in June 2016 I posted Basic formula accuracy
-
It was using the old
numeral.js
(which I had to stick with), before it got replaced bynumbro.js
, but I would guess the same JavaScript restriction persists. So it may be that what you are seeing with your numbers is a JavaScript arithmetic round error. -
For the record, to the best of my knowledge Hot/numeral/numbro specification of output still does not allow a format of “as many decimal places as required” or “up to but not more than 4 decimal places”, so be aware of that in what you are trying to achieve.
-
I found that waiting for a response to an issue like this was better handled by stepping through the code myself in debugger, seeing what was going on in the source to understand, and fixing if necessary. You can do this easily with the numbro code used — just make sure you are including
numbro.js
notnumbro.min.js
— it’s really not too hard. For example, from what you report there may be different code involved in the output format of a number in edit/validate mode versus in view mode. Your choice.