Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2941
  • Last Modified:

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
0
CodeHead
Asked:
CodeHead
1 Solution
 
Michel PlungjanIT 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

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now