Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I format numbers to have only two decimal places?

Tags:

php

mysql

I want that real numbers would be for example 12.92, but not 12.9241. Is it possible to do like that?

like image 211
good_evening Avatar asked Jan 02 '10 18:01

good_evening


1 Answers

In PHP, try number_format:

$n = 1234.5678;

// Two decimal places, using '.' for the decimal separator
// and ',' for the thousands separator.
$formatted = number_format($n, 2, '.', ',');
// 1,234.57
like image 113
John Feminella Avatar answered Oct 29 '22 07:10

John Feminella