I have a simple math formula that works beautifully (see code below) However, on some occasions where there is a second zero after the decimal point, it does not show up (ie-$100.1 should be $100.10). Is there a way to ensure that the second number displays even if it is zero?
<?php
if (($_POST['age'] >= 18) && ($_POST['age'] <= 25) && ($_POST['sex'] =="male"))
$quote=31.44;
elseif (($_POST['age'] >= 18) && ($_POST['age'] <= 25) && ($_POST['sex'] =="female"))
$quote=44.65;
elseif (($_POST['age'] >= 26) && ($_POST['age'] <= 30) && ($_POST['sex'] =="male"))
$quote=35.91;
elseif (($_POST['age'] >= 26) && ($_POST['age'] <= 30) && ($_POST['sex'] =="female"))
$quote=50.33;
elseif (($_POST['age'] >= 31) && ($_POST['age'] <= 35) && ($_POST['sex'] =="male"))
$quote=40.78;
elseif (($_POST['age'] >= 31) && ($_POST['age'] <= 35) && ($_POST['sex'] =="female"))
$quote=62.11;
elseif (($_POST['age'] >= 36) && ($_POST['age'] <= 40) && ($_POST['sex'] =="male"))
$quote=51.33;
elseif (($_POST['age'] >= 36) && ($_POST['age'] <= 40) && ($_POST['sex'] =="female"))
$quote=76.72;
elseif (($_POST['age'] >= 41) && ($_POST['age'] <= 45) && ($_POST['sex'] =="male"))
$quote=65.95;
elseif (($_POST['age'] >= 41) && ($_POST['age'] <= 45) && ($_POST['sex'] =="female"))
$quote=92.55;
elseif (($_POST['age'] >= 46) && ($_POST['age'] <= 50) && ($_POST['sex'] =="male"))
$quote=87.87;
elseif (($_POST['age'] >= 46) && ($_POST['age'] <= 50) && ($_POST['sex'] =="female"))
$quote=108.38;
elseif (($_POST['age'] >= 51) && ($_POST['age'] <= 60) && ($_POST['sex'] =="male"))
$quote=117.51;
elseif (($_POST['age'] >= 51) && ($_POST['age'] <= 60) && ($_POST['sex'] =="female"))
$quote=126.65;
elseif (($_POST['age'] >= 61) && ($_POST['age'] <= 64) && ($_POST['sex'] =="male"))
$quote=184.07;
elseif (($_POST['age'] >= 61) && ($_POST['age'] <= 64) && ($_POST['sex'] =="female"))
$quote=168.87;
//add spouse
if (($_POST['spouse_age'] >= 18) && ($_POST['spouse_age'] <= 25) && ($_POST['spouse_sex'] =="male"))
$quote+=31.44;
elseif (($_POST['spouse_age'] >= 18) && ($_POST['spouse_age'] <= 25) && ($_POST['spouse_sex'] =="female"))
$quote+=44.65;
elseif (($_POST['spouse_age'] >= 26) && ($_POST['spouse_age'] <= 30) && ($_POST['spouse_sex'] =="male"))
$quote+=35.91;
elseif (($_POST['spouse_age'] >= 26) && ($_POST['spouse_age'] <= 30) && ($_POST['spouse_sex'] =="female"))
$quote+=50.33;
elseif (($_POST['spouse_age'] >= 31) && ($_POST['spouse_age'] <= 35) && ($_POST['spouse_sex'] =="male"))
$quote+=40.78;
elseif (($_POST['spouse_age'] >= 31) && ($_POST['spouse_age'] <= 35) && ($_POST['spouse_sex'] =="female"))
$quote+=62.11;
elseif (($_POST['spouse_age'] >= 36) && ($_POST['spouse_age'] <= 40) && ($_POST['spouse_sex'] =="male"))
$quote+=51.33;
elseif (($_POST['spouse_age'] >= 36) && ($_POST['spouse_age'] <= 40) && ($_POST['spouse_sex'] =="female"))
$quote+=76.72;
elseif (($_POST['spouse_age'] >= 41) && ($_POST['spouse_age'] <= 45) && ($_POST['spouse_sex'] =="male"))
$quote+=65.95;
elseif (($_POST['spouse_age'] >= 41) && ($_POST['spouse_age'] <= 45) && ($_POST['spouse_sex'] =="female"))
$quote+=92.55;
elseif (($_POST['spouse_age'] >= 46) && ($_POST['spouse_age'] <= 50) && ($_POST['spouse_sex'] =="male"))
$quote+=87.87;
elseif (($_POST['spouse_age'] >= 46) && ($_POST['spouse_age'] <= 50) && ($_POST['spouse_sex'] =="female"))
$quote+=108.38;
elseif (($_POST['spouse_age'] >= 51) && ($_POST['spouse_age'] <= 60) && ($_POST['spouse_sex'] =="male"))
$quote+=117.51;
elseif (($_POST['spouse_age'] >= 51) && ($_POST['spouse_age'] <= 60) && ($_POST['spouse_sex'] =="female"))
$quote+=126.65;
elseif (($_POST['spouse_age'] >= 61) && ($_POST['spouse_age'] <= 64) && ($_POST['spouse_sex'] =="male"))
$quote+=184.07;
elseif (($_POST['spouse_age'] >= 61) && ($_POST['spouse_age'] <= 64) && ($_POST['spouse_sex'] =="female"))
$quote+=168.87;
//add children
if (($_POST['children'] >= 3))
$quote+=90.12;
elseif (($_POST['children'] == 1))
$quote+=30.04;
elseif (($_POST['children'] == 2))
$quote+=60.08;
elseif (($_POST['children'] == 3))
$quote+=90.12;?>
//quote value
echo "<p style='font-size:60px; color:#b7cd2d;'>$".$quote."
";
echo "<span style='font-size:16px;'>per month*</span></p>";
?>
Math - Display two numbers after decimal point $100.00
Moderator: General Moderators
-
ringartdesign
- Forum Newbie
- Posts: 21
- Joined: Wed Sep 10, 2008 10:11 am
Re: Math - Display two numbers after decimal point $100.00
Use number_format().
Re: Math - Display two numbers after decimal point $100.00
Code: Select all
sprintf()
or
number_format()
There are 10 types of people in this world, those who understand binary and those who don't
-
ringartdesign
- Forum Newbie
- Posts: 21
- Joined: Wed Sep 10, 2008 10:11 am
Re: Math - Display two numbers after decimal point $100.00
Hey, thanks!
I used the below amendment and it displayed everything before the decimal point, but not after $100, but no $100.00. How can I change this?
echo "<p style='font-size:60px; color:#b7cd2d;'>$".number_format($quote)."<br />";
I used the below amendment and it displayed everything before the decimal point, but not after $100, but no $100.00. How can I change this?
echo "<p style='font-size:60px; color:#b7cd2d;'>$".number_format($quote)."<br />";
Re: Math - Display two numbers after decimal point $100.00
With questions like that you really should read the PHP manual first. It's much quicker than posting here and waiting for someone to respond.
-
ringartdesign
- Forum Newbie
- Posts: 21
- Joined: Wed Sep 10, 2008 10:11 am
Re: Math - Display two numbers after decimal point $100.00
will do...thanks anyways
(tail between my legs)
(tail between my legs)
Re: Math - Display two numbers after decimal point $100.00
try
number_format($poopoo,2);
number_format($poopoo,2);