[Solved] Trim zeros from decimal part php

You can use substr() function also to remove last char if it is 0. May be the below code will help you function roundit($string) { $string = number_format($string,2); if (substr($string, -1, 1) == ‘0’) { $string = substr($string, 0, -1); echo $string; } else echo $string; } roundit(‘150.00’); roundit(‘150.10’); roundit(‘150.76’); 4 solved Trim zeros from … Read more

[Solved] format a 12 digit number in XXXX XXXX XXXX format using javascript

You can use selectionEnd to control the position of cursor var target = document.querySelector(‘.creditCardText’); target.addEventListener(“keyup”, function() { var position = target.selectionStart; var prevVal = target.value; var newVal = prevVal.split(” “).join(“”); // remove spaces if (newVal.length > 0) { newVal = newVal.match(new RegExp(‘.{1,4}’, ‘g’)).join(” “); } target.value = newVal; for (var i = 0; i < … Read more

[Solved] Convert Yards to Miles, Furlongs and Yards

Never mind, figured it out. const furlongToYard = 220; const mileToYard = 1760; class Distance { yardsToMilesAndFurlongsReadable(yards) { let miles = Math.floor(yards / mileToYard); yards = yards % mileToYard; let furlongs = Math.floor(yards / furlongToYard); yards = yards % furlongToYard; return `${miles > 0 ? miles + ‘m’ : ”} ${furlongs > 0 ? furlongs … Read more

[Solved] php numbers like (10M, ..)

You could whip up your own function, because there isn’t an builtin function for this. To give you an idea: function strtonum($string) { $units = [ ‘M’ => ‘1000000’, ‘K’ => ‘1000’, ]; $unit = substr($string, -1); if (!array_key_exists($unit, $units)) { return ‘ERROR!’; } return (int) $string * $units[$unit]; } Demo: http://codepad.viper-7.com/2rxbP8 Or the other … Read more