two decimal places
As an example it currently outputs as 127.1 instead of 127.10.
Can anyone look at the snippet of code and show me how please?
var raise = Math.pow(10,2);
value = Math.round(value * raise) / raise;
var totalArea = ((frm.area1width.value * frm.area1length.value);
var totalCostSand = totalArea * sandCost;
<p style="text-align: right;">cost for sanding £
<input name="totalCostSand" type="text" class="input" style="width: 50px;" readonly="readonly" />
var totalCostSand= frm.area1width.value*frm.area1length.value*sandCost;
Important note: number.toFixed(decimal places | integer) returns a string.
Ah so if I wanted to pass the result to a shopping cart then it could cause me problems then?
Originally Posted by jamesbcox1980
You are using the string as a form field value-all form field values are strings.
The server (presumably) will convert it to a number.
Thanks for clearing that up
Yeah you should be fine. mrhoo said it best. I just wanted you to keep that in mind in case you decided to use it in math somewhere else. I remember running into an issue with that along time ago thinking that it returned a number as a se point variable.
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)