infobih
Posts: 58
|
| Posted: 12/30/2009, 3:42 AM |
|
Hi all
Look at example pack "Master-Detail Form for Order Entry" on http://examples.codecharge.com/ExamplePack/OrderEntry/OrderEntry.php
How can force JavaScript to always show two decimal places for "Price" and "Total" as it is for "Unit Price", even if it is ex. 12.90 instead 12.9
This is javascript used in the page:
<script language="JavaScript" type="text/javascript">
function StrToFloat(str)
{
if (str.indexOf(",") != -1) {
str = str.replace(",",".");
}
var result = parseFloat(str);
if (isNaN(result)) {
result = 0.00;
}
return (result);
}
function Show_Total()
{
var TotalSum=0;
var Summ;
for(var i = 0; i < store_orders_itemsElements.length; i++){
Summ = StrToFloat(store_orders_itemsElements[store_orders_itemspriceID].value) *
StrToFloat(store_orders_itemsElements[store_orders_itemsquantityID].value);
TotalSum = TotalSum + Summ;
if (Summ == 0) {
store_orders_itemsElements[store_orders_itemsSumPriceID].value = "";
} else {
store_orders_itemsElements[store_orders_itemsSumPriceID].value = Math.round(Summ*100)/100;
}
}
document.store_orders_items.Total_price.value = Math.round(TotalSum*100)/100;
}
|
 |
 |
computerman
Posts: 27
|
| Posted: 01/15/2010, 3:32 PM |
|
Check this out: http://www.w3schools.com/jsref/jsref_tofixed.asp
_________________
"whoever is a cruel, must be an old downtrod who has got authority,
whoever is a downtrod, must be an old cruel who has lost authority. "
An Oriental Saying |
 |
 |
infobih
Posts: 58
|
| Posted: 01/16/2010, 12:11 AM |
|
Thank you for answer.
I did try this before. I think it will do it job - function (num.toFixed(2), but i dont know where to put exactly in my script. I am noy sucessfull.
Can you help if you know Javascript.
|
 |
 |
|