1

Can anyone please suggest a way to delete all zeros after the decimal point.

I need the numbers to be changed as following:

 232.20 should be converted to 232.2
 232.00 should be converted to 232
 232.22 should be the same

does number_format() help in any way?

Abhi
  • 4,123
  • 6
  • 45
  • 77
ashwin
  • 27
  • 6
  • Check this answer http://stackoverflow.com/a/14531760/2968762 – Abhi Dec 28 '16 at 09:01
  • 3
    Possible duplicate of [Remove useless zero digits from decimals in PHP](http://stackoverflow.com/questions/14531679/remove-useless-zero-digits-from-decimals-in-php) – Abhi Dec 28 '16 at 09:01

3 Answers3

2

Just use floatval( your_value )

Ultrazz008
  • 1,678
  • 1
  • 13
  • 26
1

You can use floatval():

echo floatval('12.00');
// 12

echo floatval('66.70');
// 66.7

echo floatval('44.011');
// 44.011
Bud Damyanov
  • 30,171
  • 6
  • 44
  • 52
1

Simply add a zero

echo 232.20 + 0; // 232.2
echo 232.00 + 0; // 232
echo 232.22 + 0; // 232.22

I have taken reference for the SO question Remove useless zero digits from decimals in PHP

Please have a look

Community
  • 1
  • 1
Passionate Coder
  • 7,154
  • 2
  • 19
  • 44