Jump to content

adding up toal cost in cart via session problem


fazz

Recommended Posts

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!

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;
        }
    }

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.