[PHP] Problem with wanting something NOT to round
Hi, As part of a result from a web-service call, I get a price in dollars and cents as a decimal number eg.160.44 (the example I am working on. This price is for permission to re-use some published material and for each additional separate pagerange, $3 needs to be added afterwards. So I have the following code in my script: $range = explode(,,$pr); $rangecounter = count($range); $rangecounter = ($rangecounter1?$rangecounter-1:0); $ccc_supp = floatval($rangecounter * 3); $fee2 = floatval($fee + $ccc_supp); echo sprintf(%01.2f,$fee2); $pr is my pagerange which, in this case is 9-24, generates a rangecounter of 1, so does not get any additional $3 added. My echo produces 160, instead of the 160.44 which I want. Can anyone point me in the direction of a solution? MTIA George -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Problem with wanting something NOT to round
George Pitcher wrote: As part of a result from a web-service call, I get a price in dollars and cents as a decimal number eg.160.44 (the example I am working on. This price is for permission to re-use some published material and for each additional separate pagerange, $3 needs to be added afterwards. So I have the following code in my script: $range = explode(,,$pr); $rangecounter = count($range); $rangecounter = ($rangecounter1?$rangecounter-1:0); $ccc_supp = floatval($rangecounter * 3); $fee2 = floatval($fee + $ccc_supp); echo sprintf(%01.2f,$fee2); $pr is my pagerange which, in this case is 9-24, generates a rangecounter of 1, so does not get any additional $3 added. My echo produces 160, instead of the 160.44 which I want. Can anyone point me in the direction of a solution? Are you sure the web service is giving you 160.44? I get it displayed as expected... http://dev.stut.net/php/pitcher.php -Stut -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Problem with wanting something NOT to round
George Pitcher wrote: Are you sure the web service is giving you 160.44? I get it displayed as expected... http://dev.stut.net/php/pitcher.php Yes, I am echoing the 160.44 ok. I'm just not getting the 44c in my display price. I'm on Windows NT - could that be a factor? I'm not sure what you mean by in my display price. Please elaborate? -Stut -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Problem with wanting something NOT to round
George Pitcher wrote: As part of a result from a web-service call, I get a price in dollars and cents as a decimal number eg.160.44 (the example I am working on. This price is for permission to re-use some published material and for each additional separate pagerange, $3 needs to be added afterwards. So I have the following code in my script: $range = explode(,,$pr); $rangecounter = count($range); $rangecounter = ($rangecounter1?$rangecounter-1:0); $ccc_supp = floatval($rangecounter * 3); $fee2 = floatval($fee + $ccc_supp); echo sprintf(%01.2f,$fee2); $pr is my pagerange which, in this case is 9-24, generates a rangecounter of 1, so does not get any additional $3 added. My echo produces 160, instead of the 160.44 which I want. Can anyone point me in the direction of a solution? Are you sure the web service is giving you 160.44? I get it displayed as expected... http://dev.stut.net/php/pitcher.php Hi, Yes, I am echoing the 160.44 ok. I'm just not getting the 44c in my display price. I'm on Windows NT - could that be a factor? George -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Problem with wanting something NOT to round
George Pitcher wrote: Are you sure the web service is giving you 160.44? I get it displayed as expected... http://dev.stut.net/php/pitcher.php Yes, I am echoing the 160.44 ok. I'm just not getting the 44c in my display price. I'm on Windows NT - could that be a factor? I'm not sure what you mean by in my display price. Please elaborate? If I paste your code (from your web-page example), into a new php file, I get 160.44. However, replacing my existing code with the example code into the page that is to do the work, I get 160.00. To simplify things, I've now done the following in the new php file and then on my page: $fee = 160.44; echo fee: .$fee.br; $fee2 = $fee + 0.00; echo fee2: .$fee2.br; I get 160.44 on the standalone page and 160.00 on my web page. I am using PHP5.1 with Smarty templates on my page (but not on the standalone page). Smarty doesn't offer anything other than the sprintf() options for string formatting of decimal numbers, and I'm already doing that. Do you think Smarty could be so unsmart as to undo the formatting? As another test, I did settype($fee2, float)then the gettype($fee2) and got 'float' on the standalone page and NULL on my Smarty page. Truly stumped! George -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Problem with wanting something NOT to round
George Pitcher wrote: I am using PHP5.1 with Smarty templates on my page (but not on the standalone page). Smarty doesn't offer anything other than the sprintf() options for string formatting of decimal numbers, and I'm already doing that. Do you think Smarty could be so unsmart as to undo the formatting? As another test, I did settype($fee2, float)then the gettype($fee2) and got 'float' on the standalone page and NULL on my Smarty page. Sounds like a question for the Smarty mailing list. -Stut -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php