Truncate

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
LVL 1
CodeHeadAsked:
Who is Participating?
 
Michel PlungjanConnect With a Mentor IT ExpertCommented:
<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
 
CodeHeadAuthor Commented:
Thanks
0
All Courses

From novice to tech pro — start learning today.