Scooby08 Posted February 19, 2011 Share Posted February 19, 2011 I have this function which is javascript and I need to convert it to php.. function US2dec(myUS) { if (myUS.toLowerCase() == 'even') { myUS = '100'; } var myDec; myUS = parseFloat(myUS); if (Math.abs(myUS) < 100 || isNaN(myUS)) { myDec = NaN; } else if (myUS > 0) { myDec = 1 + myUS / 100; } else { myDec = 1 - 100 / myUS; } return myDec.toFixed(; } I came up with this php version and it seems to work but I'm no expert with math functions.. I was hoping somebody who's a bit more familiar with these functions could check it over quick.. function US2dec($myUS) { if (strtolower($myUS) == 'even') { $myUS = 100; } $myDec = 0; $myUS = floatval($myUS); if (abs($myUS) < 100 || !is_numeric($myUS)) { $myDec = 0; } else if ($myUS > 0) { $myDec = 1 + $myUS / 100; } else { $myDec = 1 - 100 / $myUS; } return number_format($myDec,; } Thanks!! Link to comment https://forums.phpfreaks.com/topic/228168-help-properly-converting-a-javascript-function-to-php/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.