| | |
Displaying decimals in JavaScript??
Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
•
•
Join Date: Oct 2008
Posts: 19
Reputation:
Solved Threads: 0
I am new to JavaScript and have what may be a very simple and easy question to most. I am writing a simple block of code that I need to display dollar amounts with 2 decimals for change. For example instead of displaying the number 5, I need it to display 5.00. How can I do this? Any help will be greatly appreciated.
hello see this code:
it will print 200 as 200.00
it will print 200 as 200.00
javascript Syntax (Toggle Plain Text)
<script language="javascript"> function CurrencyFormatted(amount) { var i = parseFloat(amount); if(isNaN(i)) { i = 0.00; } var minus = ''; if(i < 0) { minus = '-'; } i = Math.abs(i); i = parseInt((i + .005) * 100); i = i / 100; s = new String(i); if(s.indexOf('.') < 0) { s += '.00'; } if(s.indexOf('.') == (s.length - 2)) { s += '0'; } s = minus + s; // alert(s); return s; } </script>
Be intelligent, But Don't try to cheat.. Be innocent But Don't get cheated..
•
•
Join Date: Oct 2008
Posts: 19
Reputation:
Solved Threads: 0
Good morning Shanti and thank you for your reply. While I did not use the code you provided because many of the characters and items were beyond my understanding, your code still did help me to get the wheels turning in my head and you helped me to solve my problem. Thanks again for your help, it was greatlyAppreciated.
![]() |
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: Iframe replacement
- Next Thread: how to maximize table cell height
| Thread Tools | Search this Thread |
Tag cloud for JavaScript / DHTML / AJAX
acid2 ajax ajaxexample ajaxhelp ajaxjspservlets animate array automatically beta blackjack boarder box captcha card cart codes column css date debugger decimal design developer dom download element embed enter error events firefox focus form frameworks getselection google gwt hiddenvalue hint html htmlform ie7 iframe image() index java javascript javascripthelp2020 javascripts jawascriptruntimeerror jquery jsp libcurl listbox maps marquee masterpage media menu microsoft mimic mp4 onerror onmouseover parameters paypal php player position post problem programming prototype rating redirect regex safari scale scriptlets search security select size software sources sql starrating textarea toggle tweet twitter unicode validation variables w3c webservice website window windowofwords xml






