ringartdesign Posted September 30, 2008 Share Posted September 30, 2008 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."<br />"; echo "<span style='font-size:16px;'>per month*</span></p>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/126469-displaying-2-numbers-after-decimal-point-ie-10000/ Share on other sites More sharing options...
Maq Posted September 30, 2008 Share Posted September 30, 2008 printf ("%01.2f", $quote); Quote Link to comment https://forums.phpfreaks.com/topic/126469-displaying-2-numbers-after-decimal-point-ie-10000/#findComment-653921 Share on other sites More sharing options...
Barand Posted September 30, 2008 Share Posted September 30, 2008 //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;?> I see there's no point in trying to help some members http://www.phpfreaks.com/forums/index.php/topic,217833.msg1000489.html#msg1000489 Quote Link to comment https://forums.phpfreaks.com/topic/126469-displaying-2-numbers-after-decimal-point-ie-10000/#findComment-654162 Share on other sites More sharing options...
PFMaBiSmAd Posted September 30, 2008 Share Posted September 30, 2008 One characteristic of a well written program is separation of code and data. If your age brackets change or the amounts change, you should not need to modify your code, only put in new data values (and I don't mean going through your source code and typing in new values in the comparisons or assignment statements.) So, at a minimum, you should be using data array(s) or you should be using a database. Quote Link to comment https://forums.phpfreaks.com/topic/126469-displaying-2-numbers-after-decimal-point-ie-10000/#findComment-654177 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.