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!

Link to comment
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.