-4

I have this number 4030.146852312

i need to get the four decimals from this percentage of this number so at the end i get

4030.1468

and transform this number according to locale

so for example

4.030,1468

how can I do this ?

Code
  • 313
  • 1
  • 2
  • 11
  • Does this answer your question? [How to round to at most 2 decimal places, if necessary?](https://stackoverflow.com/questions/11832914/how-to-round-to-at-most-2-decimal-places-if-necessary) (The solutions there can easily be changed to 4 decimal places) – DBS Dec 13 '21 at 14:23
  • No, i need always four decimals – Code Dec 13 '21 at 14:25
  • So, where exactly are you stuck? There are countless questions covering JS rounding, and a quick search for "JS convert number to locale string" brings up everything you should need for the formatting. – DBS Dec 13 '21 at 14:33

1 Answers1

1

You can easly use Intl.NumberFormat object:

const number = 4030.1468;

console.log(new Intl.NumberFormat('de-DE', { minimumFractionDigits: 4, maximumFractionDigits: 4 }).format(number));

For more info https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat

Giovanni Esposito
  • 10,696
  • 1
  • 14
  • 30