0

How can I format a number respecting the last two number as decimals?

1000 -> 10,00

123456 -> 1.234,56

I am trying the code below but it won't work keeping the last two places as decimals.

fromat(value) {
             return value === null ? "0,00" :  Numeral(value).format('0,0[.]00');
            },

Thank you.

Low Rider
  • 183
  • 1
  • 1
  • 11
  • 2
    There are numerous examples on [their website](http://numeraljs.com/), along with [information about registering locales](http://numeraljs.com/#locales). Please show what you've tried or what it is you don't understand. – Heretic Monkey May 18 '20 at 13:54
  • @HereticMonkey I am using format('0,0[.]00'); - And it won't work. They don't have an example in their page about this format. – Low Rider May 18 '20 at 13:57
  • Look at the second link. There are options for `delimiters`: `thousands` and `decimal`. Using a little logic, one should come up with appropriate values to set those options to, to produce the desired outcome. – Heretic Monkey May 18 '20 at 14:01

1 Answers1

0

Here is my solution:

Numeral(`${value.toString().slice(0, -2)}.${value.toString().slice(-2)}`).format('$ 0,0.00')
Low Rider
  • 183
  • 1
  • 1
  • 11