Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

PHP function issue

Posted on 2013-06-09
5
Medium Priority
?
299 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 30

Assisted Solution

by:Randy Downs
Randy Downs earned 668 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 84

Assisted Solution

by:Dave Baldwin
Dave Baldwin earned 664 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 111

Accepted Solution

by:
Ray Paseur earned 668 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
This article discusses how to implement server side field validation and display customized error messages to the client.
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 and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

885 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