Solved

Truncate

Posted on 2000-04-06
2
2,934 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…

828 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