This week's book giveaway is in the HTML/CSS/JavaScript forum.
We're giving away four copies of Practical SVG and have Chris Coyier on-line!
See this thread for details.
Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Quick question

 
joew weakers
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there. This is a really quick one. If I have a float value 3.5711762E-6,
how do I just return the number to four decimal places, i.e. 3.5718. Cheers, Joe
 
Steven Bell
Ranch Hand
Posts: 1071
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Probably have to convert it to a string and then use subString to get the right number of digits. If you were to use BigDecimal I think it has methods that do that for you.
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It depends on how you want to use the rounded version. If you are simply displaying the value, then you should use the NumerFormat class. If you need to round a number for calculations, you should look at the round() method in the Math class.

HTH

Layne
[ February 28, 2005: Message edited by: Layne Lund ]
 
You have to be odd to be #1 - Seuss. An odd little ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!