Currency format in php?

I am looking at the money_format function in php and am confused about how to format it the way I want. I do not want USD in front of my line, I want to change 123 will be formed until 123.00

thanks

+4
source share
4 answers

Use this money_format("%!.2n", 123) ! suppresses the currency symbol from output, as it is written in the documentation money_format

+3
source

You need something like this

 setlocale(LC_MONETARY, 'en_US'); $money = 123; echo money_format( '%!#4.2i', $money ); 

To explain the format string:

  • %, this is the required first character
  • !, it suppresses the currency symbol,
  • # 4, this means that we will have a maximum of 4 digits to the left of the decimal fraction and will be properly justified,
  • .2, this indicates 2 decimal places,
  • i is a required character that defines conversion characters.
+1
source

Or try sprintf [1], for example:

 sprintf("%.2f", 123.1); 

[1] http://php.net/manual/en/function.sprintf.php

0
source

Source: https://habr.com/ru/post/1388722/


All Articles