File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

confusion in division

 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all;

in maths,

22/12=1.833..

i want to get the answer(1.833) in java...is ther any special function


i want to get output..but i can not ..please helpme..

thanks & regards,
seetharaman
 
Ulf Dittmer
Rancher
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you use "22/12", the JVM assumes that you want an integer result, because both numbers are integer. If you write "22.0/12" or "22/12.0" you will get a floating-point result.
 
Chiranjeevi Kanthraj
Ranch Hand
Posts: 290
Hibernate Spring Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i know this is not the good solution for your problem.
i think it will slove your problem
String a=""+22/12.0;//take in a String
System.out.println(new Float(a.substring(0,5))); //take the required value convert it to Float
 
Ulf Dittmer
Rancher
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by chiru surya:
...

Don't do this. For formatted printing you can use System.out.printf, and for in-memory formatting you can use the java.text.NumberFormat class. Both have plenty of options for formatting the number.
 
Chiranjeevi Kanthraj
Ranch Hand
Posts: 290
Hibernate Spring Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
formatting the number

Thank for this
 
Rob Spoor
Sheriff
Pie
Posts: 20381
46
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by chiru surya:
String a=""+22/12.0;//take in a String

Never ever ever do that again. The 22/12.0 part will be converted to a string, then added to the empty string. From now on, just call String.valueOf(22/12.0) - the resulting string will be the same but there will be fewer objects created.
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks ulf Dittmer
 
Chiranjeevi Kanthraj
Ranch Hand
Posts: 290
Hibernate Spring Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Never ever ever do that again.

Thanks man.
for this good Suggestion. Really thanks
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic