Solved

Truncate

Posted on 2000-04-06
2
2,933 Views
Last Modified: 2007-10-18
How can you truncate a Number.

Example I am getting back a number like

10203.200392991

Or course this makes no sense to the user.  They need to see 10203.20
0
Comment
Question by:CodeHead
2 Comments
 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 10 total points
ID: 2692517
<HTML>
<SCRIPT>
function ToDollarsAndCents(n) {
   var s = "" + Math.round(n * 100) / 100
   var i = s.indexOf('.')
   if (i < 0) return s + ".00"
   var t = s.substring(0, i + 1) + s.substring(i + 1, i + 3)
   if (i + 2 == s.length) t += "0"
   return t
}
a=6.02
b=3.01
alert((a-b)+':'+ToDollarsAndCents(a-b));
</SCRIPT></HTML>

Michel
PS: Are you low on points??
0
 
LVL 1

Author Comment

by:CodeHead
ID: 2696389
Thanks
0

Featured Post

ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question