fazz Posted December 17, 2007 Share Posted December 17, 2007 I have a shopping cart, and each client that logs on has a budget spend - am testing it with a budget of 5000. So I have created this that works until the toal goes past 999 <?php $Budget = $HTTP_GET_VARS['Budget']; $TotalCart = $HTTP_SESSION_VARS["icNamco"]->col("Total"); echo number_format ($Budget - $TotalCart); ?> It deducts and gives me the correct total until it goes over 999 and the reverts to displaying 4,999 Can any one shine any light on this! Merry christmas to everyone! Link to comment https://forums.phpfreaks.com/topic/82005-adding-up-toal-cost-in-cart-via-session-problem/ Share on other sites More sharing options...
VirusDoctor Posted December 17, 2007 Share Posted December 17, 2007 Hi fazz, I'm no super php guru but from what I can see, you're trying to subtract what php thinks is two strings from each other. You would need to turn the strings into integers first (probably through type casting) and then tell php to to echo the total with a float. The following code is not mine but it may prove useful for this: <?php function strtonumber( $str, $dec_point=null, $thousands_sep=null ) { if( is_null($dec_point) || is_null($thousands_sep) ) { $locale = localeconv(); if( is_null($dec_point) ) { $dec_point = $locale['decimal_point']; } if( is_null($thousands_sep) ) { $thousands_sep = $locale['thousands_sep']; } } $number = (float) str_replace($dec_point, '.', str_replace($thousands_sep, '', $str)); if( $number == (int) $number ) { return (int) $number; } else { return $number; } } ?> Link to comment https://forums.phpfreaks.com/topic/82005-adding-up-toal-cost-in-cart-via-session-problem/#findComment-416665 Share on other sites More sharing options...
fazz Posted December 17, 2007 Author Share Posted December 17, 2007 Thanks? Had a look at this and im no guru! Can't see the wood fortrees today, must be an xmas thing! Link to comment https://forums.phpfreaks.com/topic/82005-adding-up-toal-cost-in-cart-via-session-problem/#findComment-416667 Share on other sites More sharing options...
fazz Posted December 17, 2007 Author Share Posted December 17, 2007 Tried this in a number of ways and I still can't get ti to work, any one else have any ideas? Link to comment https://forums.phpfreaks.com/topic/82005-adding-up-toal-cost-in-cart-via-session-problem/#findComment-416668 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.