473,406 Members | 2,352 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

How to have 2 decimal places on a price calculator

I have a price calculator, and I need to have it contain 2 decimal places when generating a quote. I tried using toFixed(2) (as you can see below) but I am not sure if I did it right. Can you help? Thanks

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2. var roomobjs = [];
  3. var roomobj = {};
  4.  
  5. roomobj.name = "Bathroom";
  6. roomobj.clean = 15;
  7. roomobj.moveFurniture = 10;
  8. roomobj.preVacuum = 5;
  9. roomobj.protect = 10;
  10. roomobjs[roomobj.name] = roomobj;
  11.  
  12. var roomobj = {};
  13. roomobj.name = "Bedroom";
  14. roomobj.clean = 30;
  15. roomobj.moveFurniture = 0;
  16. roomobj.preVacuum = 10;
  17. roomobj.protect = 15;
  18. roomobjs[roomobj.name] = roomobj;
  19.  
  20. var roomobj = {};
  21. roomobj.name = "Dining Room";
  22. roomobj.clean = 30;
  23. roomobj.moveFurniture = 20;
  24. roomobj.preVacuum = 10;
  25. roomobj.protect = 15;
  26. roomobjs[roomobj.name] = roomobj;
  27.  
  28.  
  29. var roomobj = {};
  30. roomobj.name = "Family Room";
  31. roomobj.clean = 30;
  32. roomobj.moveFurniture = 20;
  33. roomobj.preVacuum = 10;
  34. roomobj.protect = 15;
  35. roomobjs[roomobj.name] = roomobj;
  36.  
  37. var roomobj = {};
  38. roomobj.name = "Hallway";
  39. roomobj.clean = 15;
  40. roomobj.moveFurniture = 0;
  41. roomobj.preVacuum = 5;
  42. roomobj.protect = 10;
  43. roomobjs[roomobj.name] = roomobj;
  44.  
  45. var roomobj = {};
  46. roomobj.name = "Kitchen";
  47. roomobj.clean = 30;
  48. roomobj.moveFurniture = 20;
  49. roomobj.preVacuum = 10;
  50. roomobj.protect = 15;
  51. roomobjs[roomobj.name] = roomobj;
  52.  
  53.  
  54. var roomobj = {};
  55. roomobj.name = "Living Room";
  56. roomobj.clean = 30;
  57. roomobj.moveFurniture = 20;
  58. roomobj.preVacuum = 10;
  59. roomobj.protect = 15;
  60. roomobjs[roomobj.name] = roomobj;
  61.  
  62. var roomobj = {};
  63. roomobj.name = "Rec Room";
  64. roomobj.clean = 30;
  65. roomobj.moveFurniture = 20;
  66. roomobj.preVacuum = 10;
  67. roomobj.protect = 15;
  68. roomobjs[roomobj.name] = roomobj;
  69.  
  70. var roomobj = {};
  71. roomobj.name = "Steps";
  72. roomobj.clean = 30;
  73. roomobj.moveFurniture = 0;
  74. roomobj.preVacuum = 10;
  75. roomobj.protect = 15;
  76. roomobjs[roomobj.name] = roomobj;
  77.  
  78.  
  79.  
  80.  
  81.  
  82.  
  83. var furnitureobjs = [];
  84. var furnitureobj = {};
  85.  
  86. furnitureobj.name = "Chair-Dining Room";
  87. furnitureobj.clean = 20;
  88. furnitureobj.preVacuum = 5;
  89. furnitureobj.protect = 10;
  90. furnitureobjs[furnitureobj.name] = furnitureobj;
  91.  
  92. var furnitureobj = {};
  93. furnitureobj.name = "Chair-Living Area";
  94. furnitureobj.clean = 39;
  95. furnitureobj.preVacuum = 5;
  96. furnitureobj.protect = 15;
  97. furnitureobjs[furnitureobj.name] = furnitureobj;
  98.  
  99. var furnitureobj = {};
  100. furnitureobj.name = "Couch";
  101. furnitureobj.clean = 69;
  102. furnitureobj.preVacuum = 10;
  103. furnitureobj.protect = 25;
  104. furnitureobjs[furnitureobj.name] = furnitureobj;
  105.  
  106. var furnitureobj = {};
  107. furnitureobj.name = "Ottoman";
  108. furnitureobj.clean = 15;
  109. furnitureobj.preVacuum = 5;
  110. furnitureobj.protect = 10;
  111. furnitureobjs[furnitureobj.name] = furnitureobj;
  112.  
  113. var furnitureobj = {};
  114. furnitureobj.name = "Sectional-'L-Shape'";
  115. furnitureobj.clean = 129;
  116. furnitureobj.preVacuum = 25;
  117. furnitureobj.protect = 30;
  118. furnitureobjs[furnitureobj.name] = furnitureobj;
  119.  
  120. var furnitureobj = {};
  121. furnitureobj.name = "Sectional-'U-Shape'";
  122. furnitureobj.clean = 159;
  123. furnitureobj.preVacuum = 25;
  124. furnitureobj.protect = 35;
  125. furnitureobjs[furnitureobj.name] = furnitureobj;
  126.  
  127.  
  128.  
  129. function renderRoomDropDown(obj)
  130. {
  131.  for(var i in roomobjs)
  132.  {
  133.   obj.append($("<option>"+roomobjs[i].name+"</option>"));
  134.  }
  135. }
  136.  
  137. function renderFurnitureDropDown(obj)
  138. {
  139.  for(var i in furnitureobjs)
  140.  {
  141.   obj.append($("<option>"+furnitureobjs[i].name+"</option>"));
  142.  }
  143. }
  144.  
  145.  
  146. function addRoomRow()
  147. {
  148.  var obj = $("<div class='record'><div class='col1'><select></select></div><div class='col2'><input type='checkbox' name='cb_clean' /> Clean</div><div class='col3'><input type='checkbox' name='cb_moveFurniture' /> Move Furniture</div><div class='col4'><input name='cb_preVacuum' type='checkbox' /> Pre-Vacuum</div><div class='col5'><input type='checkbox' name='cb_protect' /> Protect</div><div class='col6 remove'><a onclick='$(this).parent().parent().remove();'>Remove</a></div><br style='clear:left;' /></div>");
  149.  renderRoomDropDown(obj.find('select'));
  150.  $("#roomHolder").append(obj);
  151. }
  152.  
  153.  
  154. function addFurnitureRow()
  155. {
  156.  var obj = $("<div class='frecord'><div class='col1'><select></select></div><div class='col2'><input type='checkbox' name='cb_clean' /> Clean</div><div class='col3'><input name='cb_preVacuum' type='checkbox' /> Pre-Vacuum</div><div class='col4'><input type='checkbox' name='cb_protect' /> Protect</div><div class='col5 remove'><a onclick='$(this).parent().parent().remove();'>Remove</a></div><br style='clear:left;' /></div>");
  157.  renderFurnitureDropDown(obj.find('select'));
  158.  $("#furnitureHolder").append(obj);
  159. }
  160.  
  161.  
  162.  
  163. $(document).ready(function()
  164. {
  165.  $('#moreInfo').hide();
  166.  addRoomRow();
  167.  addRoomRow();
  168.  addRoomRow();
  169.  addFurnitureRow();
  170.  addFurnitureRow();
  171. });
  172.  
  173. function calculate()
  174. {
  175.  var total = 0;
  176.  $('.record').each(function(i,e)
  177.  {
  178.   var rowTotal = 0;
  179.   var roomName = $(e).find('select').val();
  180.   var clean = roomobjs[roomName].clean;
  181.   if($(e).find("input[name='cb_clean']").attr('checked')=='checked')
  182.   {
  183.    rowTotal += clean;
  184.   }
  185.   var moveFurniture = roomobjs[roomName].moveFurniture;
  186.   if($(e).find("input[name='cb_moveFurniture']").attr('checked')=='checked')
  187.   {
  188.    rowTotal += moveFurniture;
  189.   }
  190.   var preVacuum = roomobjs[roomName].preVacuum;
  191.   if($(e).find("input[name='cb_preVacuum']").attr('checked')=='checked')
  192.   {
  193.    rowTotal += preVacuum;
  194.   }
  195.   var protect = roomobjs[roomName].protect;
  196.   if($(e).find("input[name='cb_protect']").attr('checked')=='checked')
  197.   {
  198.    rowTotal += protect;
  199.   }
  200.   total += rowTotal;
  201.  });
  202.  
  203.  $('.frecord').each(function(i,e)
  204.  {
  205.   var rowTotal = 0;
  206.   var furnitureName = $(e).find('select').val();
  207.   var clean = furnitureobjs[furnitureName].clean;
  208.   if($(e).find("input[name='cb_clean']").attr('checked')=='checked')
  209.   {
  210.    rowTotal += clean;
  211.   }
  212.   var preVacuum = furnitureobjs[furnitureName].preVacuum;
  213.   if($(e).find("input[name='cb_preVacuum']").attr('checked')=='checked')
  214.   {
  215.    rowTotal += preVacuum;
  216.   }
  217.   var protect = furnitureobjs[furnitureName].protect;
  218.   if($(e).find("input[name='cb_protect']").attr('checked')=='checked')
  219.   {
  220.    rowTotal += protect;
  221.   }
  222.   total += rowTotal;
  223.  });
  224.  var length = $('#length').val();
  225.  var width = $('#width').val();
  226.  total = total + (length*width*.75);
  227.  /* sids change */
  228.  if(total<95) total = 95;
  229.  return total;
  230. }
  231.  
  232.  
  233. function doCalculate()
  234.  {
  235.  var total = calculate();
  236.  $('#moreInfo').show();
  237.  $('#total').html("$"+total);
  238.  if(total<95)
  239.  {
  240.  $("input[type='submit']").attr('disabled',true);
  241.  }
  242.  else
  243.  {
  244.  $("input[type='submit']").removeAttr('disabled');
  245.  }
  246.  $("input[name='mytotal']").val(calculate());
  247.  }
  248. mytotal.val = calculate.toFixed(2)
  249.  
  250.  
  251. </script>
Apr 2 '12 #1
1 1130
Dormilich
8,658 Expert Mod 8TB
I think that’s your least problem.

first and foremost, mytotal is undefined. then there is roomobj and furnitureobj, which you overwrite half a dozen times and which is not an array. this and more you can find in your browser’s Error Console.
Apr 2 '12 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Brent Bortnick | last post by:
Does anyone know how to find out the number of decimal places a number has. I need this info so that i can round to 3 decimal places if the number has 3 decimal places or to 2 decimal places if...
3
by: android | last post by:
I require a function that takes a double as a parameter and returns the number of decimal places. What is the most efficient way in c# to find out the number of decimal places I have written a...
2
by: Scott | last post by:
I want to display a decimal as a currency value for instance £65.00 or £58.47, but at the moment the code doesn't seem to work correctly. Can I declare this variable to be shown with 2 decimal...
4
by: Hank | last post by:
Hello, I'm running Access 2000. I would like to know if its possible to use VBA code to determine how many decimal places are specified for each table field. Currently I loop throught the...
19
by: VK | last post by:
http://groups.google.com/group/comp.lang.javascript/browse_frm/thread/ b495b4898808fde0> is more than one month old - this may pose problem for posting over some news servers. This is why I'm...
2
by: hunslair | last post by:
This is a really basic question. I am taking a teach yourself beginners course on Access 2003 and have run into a road block on one practice. In a select query, I have created a simple calculation...
3
by: Andrus | last post by:
I have lot of columns in database like Price Numeric(5,2) Street Character(30) For UI display and validation I need to retrieve width and for numeric properties, decimal places of ...
3
by: jamesnkk | last post by:
I have a currency field Total_Amount in the form,it display at 2 decimal places, but if i click on the field, it display 4 decimal places. How do I not show 4 decimal places but only show 2...
3
by: David | last post by:
Any ideas why this statement: mBalanceChange = Double.Parse(strCurrentBalance, Globalization.NumberStyles.AllowThousands Or Globalization.NumberStyles.AllowDecimalPoint) - mBalanceDouble ...
4
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I format a Number as a String with exactly 2 decimal places?...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.