Dygne
Dygne

Reputation: 237

PHP - Can't remove decimals when printing a number

in my app I have a table where I render some data. One of the table field renders a number, which is displayed like this: 8.300,0.

This is the way I'm printing it:

<td class="ex"><span>< ?php echo round($value['data'][0]); ?></span></td>

I've tried with number_format function also, how can I get rid of the decimal part?

Thanks!

Upvotes: 1

Views: 42

Answers (2)

Ben Hillier
Ben Hillier

Reputation: 2104

To round down:

echo floor($value['data'][0]);

To round up:

echo ceil($value['data'][0]);

To round off:

echo sprintf('%d', $value['data'][0]);

To get the result into European format, use the choosen function above and then:

number_format ( $result, 0 , ',' , '.' ); //Where $result is the result of the previous function.

Upvotes: 1

Afshan Shujat
Afshan Shujat

Reputation: 551

Try this -

<td class="ex"><span><?php list($number, $extra) = explode(',', '8.00,0');echo round($number); ?></span></td>

Hope this will help you.

Upvotes: 2

Related Questions