Numeric type with arbitrary number of decimal places

Tags: #<Tag:0x00007efc6151f680>

I am surprised at Handsontable’s display of numbers with decimal places, when you declare type: "numeric".

Firstly, if you type in 56.78 it displays 57. It rounds to nearest integer. I really think the documentation should at least draw attention to that default behaviour.

Secondly, there does not seem to be any way to display a number with whatever decimal places the user happens to type? To get 56.78 displayed as such I must add format: "0.00", which specifies precisely 2 decimal places. However, suppose user enters 5, 6.7 and 7.8965 in 3 other cells. I do not want rounding to a fixed number of decimal places, and I do not want trailing zeroes at the right. I cannot find any way of achieving that? Seems extraordinary.

Note: I have to keep using Hot 0.25, and hence numeraljs. However, from what I can see of the examples of the new numbrojs it seems to behave exactly the same anyway. Do either of them allow arbitrary decimal places?

Hi @jon
That’s right the numeralJS and numbroJS have the same core system so this calculations are exactly the same.

I understand your position - I had the same problem while creating a demo for a Client. The only way would be currently to write a custom editor but it’s really a lot of work.

I was just thinking… maybe there’s ability to use afterChange hook with the edit type of change to trigger a different format for this particular cell. It will stay numeric but also will apprear as you wanted. If you have time to test this I’d be happy to help with any possible issues.

@aleksandra_budnik
It’s a ridiculous limitation/oversight in numeraljs/numbrojs to not have a format that is “just print the number with whatever decimals places it has”!

I don’t suppose you’ll want to do this, but really you do not want to be fiddling with Hot hooks etc. for something so straightforward — you’d be better editing numbrojs to just make it able to do that with something in the specified format! (I would not be able to take something which caused a change to an individual cell’s format after edit.)

I was curious about numbro abilities and in their docs I found an unformat method (source: http://numbrojs.com/format.html) I think that this could be what we were looking for but I have to test it.

I’ve also added this task marked as a ‘change’ to our Github board: https://github.com/handsontable/handsontable/issues/3645

If you think that I’m missing some crucial information or suggestions please feel free to add your comment at https://github.com/handsontable/handsontable/issues/3645

I don’t mind how you do it, so long as I can set a setting/option to achieve it! I don’t want to be writing code. I think you might be suggesting that { format: false} on a { type: "numeric" } could be used to do the trick (internally you will be calling, unformat()), that is fine :slight_smile:

TBH, the fact that numeraljs/numbrojs seems to have { format: "0,0" } as its default, unless you specify otherwise — meaning that all floating point numbers are rounded to integers — is a bit bizarre in a spreadsheet application. You perhaps do not want to change that because of existing users, but the documentation could at least point that out, IMHO.

Thanks.