Last post Feb 09, 2017 06:34 AM by kaushalparik27
Member
399 Points
1101 Posts
Feb 09, 2017 06:19 AM|asp.ambur|LINK
Hello
This is my javscript
<script type="text/javascript" language="javascript"> function CalcAmount(quantity, price, amount) { document.getElementById(amount).value = parseFloat(document.getElementById(quantity).value) * parseFloat(document.getElementById(price).value); } </script>
how to round for any digit
For example output
sometimes it comes like 38.366666 i want to round 36
Sometime it comes like this 38.9 i want to round 40
All-Star
31362 Points
7055 Posts
Feb 09, 2017 06:34 AM|kaushalparik27|LINK
Use Math.round() - JavaScript | MDN
Sample Code:
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <script type="text/javascript" language="javascript"> function CalcAmount(quantity, price, amount) { var num = parseFloat(document.getElementById(quantity).value) * parseFloat(document.getElementById(price).value); document.getElementById(amount).value = Math.round(num * 100) / 100 } </script> </head> <body> <form id="form1" runat="server"> <div> <input type="text" id="quantity" /> <input type="text" id="price" /> <input type="button" value="calc" onclick="CalcAmount('quantity', 'price', 'amount')" /> <input type="text" id="amount" /> </div> </form> </body> </html>
hope that helps./.
Member
399 Points
1101 Posts
Round Javascript Result Set with two digit
Feb 09, 2017 06:19 AM|asp.ambur|LINK
Hello
This is my javscript
how to round for any digit
For example output
sometimes it comes like 38.366666 i want to round 36
Sometime it comes like this 38.9 i want to round 40
All-Star
31362 Points
7055 Posts
Re: Round Javascript Result Set with two digit
Feb 09, 2017 06:34 AM|kaushalparik27|LINK
Use Math.round() - JavaScript | MDN
Sample Code:
hope that helps./.
[KaushaL] Blog Twitter [MS MVP 2008 & 2009] [MCC 2011] [MVP Reconnect 2017]
Don't forget to click "Mark as Answer" on the post that helped you