View Single Post
Old 07-11-2004, 05:08 PM   #2 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,470
sde is on a distinguished road
number_format returns a string. the problem is when it adds a ',' in the number, php doesn't know how to cast it back and handle it as a float.

if you converted 11,250.00 to a float, it drops everything off past the first ',', resulting in 11.

i just made those seperate variables since you are just doing that to print to the screen.
PHP Code:
    for ($i=0;$i<30;$i++){
        
$quantity += $_POST['q'.$i];
    }    
    print 
"<div class='center-text'><b>Number of Books:</b> ".$quantity."</div>";

    for (
$i=0;$i<30;$i++){
        
$fmvtotal += $_POST['fmv'.$i];
    }
    
    
$fmvtotal_string number_format($fmvtotal2);    
    print 
"<div class='center-text'><b>FMV Total $:</b> ".$fmvtotal_string."</div>"

    if (
$fmvtotal >= && $fmvtotal <= 100) {
      
$ins 3.50;
    } elseif (
$fmvtotal 100.0) {
      
$ins = ( ceil( ( $fmvtotal 100) / 100 ) * 0.45) + 3.50;
    } else {
      
$ins 0;
    }
    
    
$ins_string number_format($ins2);
    print 
"<div class='center-text'><b>Insurance Total $:</b> ".$ins_string."</div>"
    
    
$servicesubtotal $_POST['service'] * $quantity;
    
    
$servicesubtotal number_format($servicesubtotal2);
    print 
"<div class='center-text'><b>Service Charges $: </b>".$servicesubtotal."</div>";

    if (
$quantity == 1) {
      
$shipping '7.40';
    } elseif (
$quantity == 2){
      
$shipping '10.90';
    } elseif (
$quantity >= && $_POST['quantity'] <= 5){
      
$shipping '14.90';
    } elseif (
$quantity 5) {
      
$shipping = (($quantity-5)*1)+14.90;
    } else {
      
$shipping 0;
    }

    
$shipping_string number_format($shipping2);
    print 
"<div class='center-text'><b>Shipping Cost:</b> ".$shipping_string."</div><br>";

    
//grand total calculation
    
$grandtotal =  $shipping+$servicesubtotal+$ins;
    
$grandtotal number_format($grandtotal2);
    print 
"<div class='center-text'><b>GRAND TOTAL$:</b> ".$grandtotal."</div>"
also, notice you don't need the $_POST[] for every variable. you should really only need to use $_POST[] when retrieving values from a form whos method is set to POST.
__________________
Mike

Last edited by sde; 07-11-2004 at 08:52 PM.
sde is offline   Reply With Quote