Solved

PHP function issue

Posted on 2013-06-09
5
289 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 109

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
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…
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…
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 …

856 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