John C
John C

Reputation: 3

PHP and dynamic number formatting

I have looked for a way to do this and have not found it.

I have values read from MySQL: 100.00, 85.50, 97.00, 71.33

I want them to display as: 100, 85.5, 97, 71.33

I see number_format() that specifies FIXED decimal places, but I need a sort of 'significant digits format'

Upvotes: 0

Views: 125

Answers (2)

Gunnrryy
Gunnrryy

Reputation: 350

use (float)$number;

$a = '100.00';
$b = 73.50;
$c = 71.33;

echo (float)$a; // 100
echo (float)$b; // 73.5
echo (float)$c; // 71.33

Upvotes: 1

Mahipal Patel
Mahipal Patel

Reputation: 543

you need to use floatval function to get your required output. just check below code.

var_dump(floatval('100.00'));
var_dump(floatval('85.50'));
var_dump(floatval('71.33'));

Upvotes: 0

Related Questions