toLocaleString()


#1

Using toLocaleString() doesn’t have expected behaviour.

On the web if you had the number 98768 and converted it to a string with toLocaleString()
it would return "98,768". But in NativeScript it just returns "98768".

Anybody else hit this issue? Why doesn’t it behave the same?

Thanks.


#2

I’m sure this isn’t “the right way” to do it but for now I’m achieving the desired outcome like so.

/*
* assuming number is equal to "98765789"
*/ 
number.split("")
      .reverse()
      .map((number, index, array) => {
        return (index+1) % 3 === 0 && array[index+1] 
            ? `,${number}` 
            : number
      })
      .reverse()
      .join("")
/*
*  number is now "98,765,789"
*/

#3

That could be upto your browser locale settings vs mobile’s.


#4

I was thinking it might be something like that. Guess that does make my current solution preferable.

Cheers.