0

What is the best way to remove zero before decimal point in php? These are the two I know of:

ltrim(0.357, '0'); //.357

preg_replace("/0\./i", ".", 0.357); //.357

Are there any better method? Which of them is faster?

TheKitMurkit
  • 463
  • 7
  • 17
  • Why you need faster way if you are using predefined functions. They already cause it to utmost fast performance. – Rahul Sep 07 '17 at 09:12

1 Answers1

0

You can do it mathematically with floor() function

$n = 0.375;
$whole = floor($n);      // 0
$fraction = $n - $whole; // .375
Osama
  • 2,912
  • 1
  • 12
  • 15