Solved

PHP function issue

Posted on 2013-06-09
5
286 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 82

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 108

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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn how to count occurrences of each item in an array.
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…

708 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now