I'm trying to trim the leading and trailing zeros from a string that contains a numeric value used to represent a percentage.
I wrote this ugly block of code that combines rtrim(), ltrim() with a preg_replace():
rtrim(ltrim(preg_replace("/\d*\.(0(?![0$])|[1-9])*\K0+$/", "", $value),"0"), ".")
But it doesn't seem to work since if I enter 0010.003000 the output is 10.003000 instead of the desired 10.003
Is there a way to make a regex read right to left in Php (delete zeros from the right until you find a zero or a [1-9])? Or is there a way to improve my regex to accomplish my goal?
Important note: For some arguable reason I can't do a simple cast to float and simply enjoy the time saved playing videogames.
To better explain my strange question here are some samples with expected behaviors: 01.00 => 1 , 100 => 100 , 002.0050 => 2.005 , 0.005 => .005