-4

If an Int is bigger than 1000, how would you go about displaying it as a currency?

1500 as an example, needs to be 1.500,00

So anything above 1000 needs to have a dot and a comma followed by 2 zero's, what's a proper way to do this?

hhffh fhfg
  • 141
  • 1
  • 1
  • 7
  • 5
    With a `number_format` function. Googling `format number php` will tell you the same. – u_mulder Oct 03 '17 at 11:56
  • 1
    Take a look at the [NumberFormatter](http://php.net/manual/en/class.numberformatter.php) class as well – apokryfos Oct 03 '17 at 11:57
  • Sorry, I meant Javascript, changed it. – hhffh fhfg Oct 03 '17 at 11:59
  • 1
    duplicate https://stackoverflow.com/questions/5731193/how-to-format-numbers-using-javascript – jens1o Oct 03 '17 at 12:00
  • 2
    Also, Stack Overflow is not a code request site. Please add your code. –  Oct 03 '17 at 12:00
  • 2
    Well then use `Number.prototype.toLocaleString()` which is the first result from googling `format number javascript`. Please read [how to ask a question](https://stackoverflow.com/help/how-to-ask) because you've done 0 research. – IsThisJavascript Oct 03 '17 at 12:00

1 Answers1

2

That's easy with the built-in php function number_format:

The first argument is the number, the second is how many decimals you'd like to have, then the seperator between the decimals and the number and then the thousand seperator.

Example:

$formattedNumber = number_format(1234, 2, ',', '.'); // => 1.234,00

More information: https://secure.php.net/manual/en/function.number-format.php

jens1o
  • 625
  • 7
  • 14