File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

SetPrecision?

 
Alfred Harre
Ranch Hand
Posts: 73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How can I set precision (say 2 decimal places) of a float ?
 
Anurag Mishra
Ranch Hand
Posts: 121
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

I don't know in what contest you want this, In case
you are showing some text input field and you want user to enter only
float till two decimal point the you can achieve this using java script.

In the function attached you need to pass the value entered by user in this Java script function
function validDecimal(str)

If User enters more than 2 decimal points, put an alert message.





thanks
Anurag
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Older versions of the JDK (pre 1.1 if I remember right) had a setPrecision method on floating point numbers. The idea was you could set the prescision of the number before you used it in any calculations. This is long since gone in favour of the java.text.NumberFormat stuff, which is precision for display only i.e. you would perform any calculations on the float as is, then format it for display to two decimal places.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic