Solved

PHP function issue

Posted on 2013-06-09
5
290 Views
Last Modified: 2013-06-10
Hello,

I have a php function:

	public function authorize(Varien_Object $payment, $amount)
	{ 
           ...
         }

Open in new window


the amount is formatted as 1,000.00 and I need it to be 1000.00.

Would I just do a str_replace ",","",$amount ?

Thanks,
Matt
0
Comment
Question by:movieprodw
5 Comments
 
LVL 29

Assisted Solution

by:Randy Downs
Randy Downs earned 167 total points
ID: 39233218
Try this. Just use amount for number

http://us1.php.net/number_format

$number = 1234.5678;

// english notation without thousands separator
$english_format_number = number_format($number, 2, '.', '');
// 1234.57
0
 
LVL 83

Assisted Solution

by:Dave Baldwin
Dave Baldwin earned 166 total points
ID: 39233227
See if your code has the money_format() function in it somewhere.  That might be what is doing it.

http://php.net/manual/en/function.money-format.php
0
 
LVL 1

Author Comment

by:movieprodw
ID: 39233239
Hello Dave,

I searched the 900 lines and no "money_format".

Number-1,

That is a good idea, better then using str_replace
0
 
LVL 110

Accepted Solution

by:
Ray Paseur earned 167 total points
ID: 39235129
formatted as 1,000.00 and I need it to be 1000.00.
You can usually use a regular expression to remove the non-numeric characters from formatted number strings.  Your expression only wants to keep digits, the decimal point, and the minus sign.  And maybe the plus sign.

Please see http://www.laprbass.com/RAY_temp_movieprodw.php

<?php // RAY_temp_movieprodw.php
error_reporting(E_ALL);


// SEE http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/Q_28152114.html


$rgx
= '#'          // REGEX DELIMITER
. '['          // START CHARACTER CLASS
. '^'          // NEGATION = MATCH NONE OF THESE
. '0-9'        // DIGITS
. '+.-'        // DECIMAL AND SIGN
. ']'          // ENDOF CHARACTER CLASS
. '#'          // REGEX DELIMITER
;

// TEST DATA
$nums = array
( '1,000.00'
, '$25.97'
, '£337'
, '-2'
)
;

// TEST THE REGULAR EXPRESSION
foreach ($nums as $num)
{
    $new = preg_replace($rgx, NULL, $num);
    echo PHP_EOL . "<br>$num => $new";
}

Open in new window

Best regards, ~Ray
0
 
LVL 1

Author Closing Comment

by:movieprodw
ID: 39235154
Hello,

Thanks for your answers, I was able to get ahold of the programmer that wrote it and he fixed it minutes before the client needed it to go live!

Thanks again for you help,
Matt
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

713 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question