0

I have this code to remove unnecessary zero in decimals :

$decimal = rtrim(sprintf('%f',floatval($decimal)),'0');

it works with these numbers :

10.0050000 -> 10.005
0.0050000 -> 0.005

but not with this :

10.00 -> 10.

there's a dot after 10.

how to remove unnecessary zero in decimals, but also works for numbers like 10.00

thanks.

Saint Robson
  • 5,364
  • 17
  • 65
  • 111
  • And [Remove useless zero digits from decimals in PHP](https://stackoverflow.com/questions/14531679/remove-useless-zero-digits-from-decimals-in-php) – Ugo T. May 16 '19 at 16:13
  • `$decimal + 0` works for all 3 – chiliNUT May 16 '19 at 16:18
  • What is the expected number then? 10 or 10.0 or 10.00? – Andreas May 16 '19 at 16:19
  • I don't understand the problem. You said you wanted to remove unnecessary zeroes, and the last example has no unnecessary zeroes. The dot is not a zero. – Barmar May 16 '19 at 16:38

0 Answers0