Jump to content

Change Money Format


unemployment

Recommended Posts

This really isn't the right scenario for preg_match(). Instead use preg_replace to remove all non-numeric characters (i.e. not digits or decimals).

 

//Remove all non numbers/decimals
$capitalrequested = preg_replace('#[^\d.]#', '', $_POST['capitalrequestedas']);
//If a valid number, round to whole nuber, else set to 0
$capitalrequested = (is_numeric($capitalrequested)) ? round($capitalrequested) : 0;

 

If the value can be negative, then the regular expression would need to be modified to retain the negative symbol.

Link to comment
https://forums.phpfreaks.com/topic/247953-change-money-format/#findComment-1273237
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.