Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

PHP function issue

Posted on 2013-06-09
5
Medium Priority
?
296 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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…

730 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