Prevent rounding when using toLocaleString


#1

Hi folks,

When I use the function toLocaleString() on the value 9999999999999999 I’m expecting it to be output as 9,999,999,999,999,999 but it’s rounded up to 10,000,000,000,000,000.

I tried to pass in the minimumFractionDigits params, for example:

toLocaleString(undefined, { minimumFractionDigits: 20 })

but that just spits out “1E+16”

Project can be seen on https://lsuah3.axshare.com/#id=ojjdeu or downloaded (47.3 KB)

Anyone know how we can prevent rounding?


#2

Treat your number as a string.


#3

Treat your number as a string.

I’m not sure what you mean. Here’s the javascript being used: [[Math.floor(Item.Column0).toLocaleString()]]

If I breakdown the flow of the javascript being used:

  1. the Math.floor() function returns an integer
  2. the toLocaleString() function then converts this integer into a formatted string.

So, if I’ve understood this flow properly, the number is being treated as a string. That’s half the purpose of using the toLocaleString() function.

Can you help me understand what I’m misunderstanding/what you mean?


#4

Integers (numbers without a period or exponent notation) are accurate up to 15 digits.


#5

Interesting…I hadn’t considered I’d reached the max number of digits for it to be accurate. It’s also interesting that it seems to be accurate up to 16 digits if the last digit is lower than 9, as shown with the variable “z” below:

An alternative approach would be to include the formatting in the repeater, so instead of storing the integer 9999999999999999 which is then converted to a string, I’d store the the string 9,999,999,999,999,999. The issue with this is that I need to be able to sort the table column as a number, so the values in the repeater need to be stored as an integer.

Does this mean the summary point of this thread is: There’s no straight-forward way of displaying 16 digit integers in a repeater in Axure that can be formatted as a currency and is sortable as a number?


#6

Hey there,
I was about to say the same, I am also facing this problem.
Review here sky west online