Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

urgent  RSS feed

 
sachin shinde
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello friends
I want to know how to make round off of any value in JSP
Ex 17.0 to 17
urgent
sachin
 
anand chawla
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
use intValue()
i mean if the variable name is x,
x.intValue() would convert it into int..
not sure though
 
sachin shinde
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
The method u told is not working.
Actually i am geting string as float ie 17.0(String)
and i have to convert it to an int.
PL reply if u know

sachin
 
Kareem Gad
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
use this :
String stringVal
int x=Integer.parseInt(stringVal);
------------------
KaReEm
 
ernest fakudze
Ranch Hand
Posts: 216
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How about explicit casting? You can cast from a float to an int.
 
Kareem Gad
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes you can do that cast but if you read the first post you'll see that the problem is that he reads a String in the form of a float so its a String in the end.
------------------
KaReEm
 
ernest fakudze
Ranch Hand
Posts: 216
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry! my mistake. It was not clear for me in the first post that we want to convert a string.
 
sanjay yermalkar
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

>>I want to know how to make round off of any value in JSP
Hi Sachin,
If you mean Rounding up a String value , i.e. 17.9 to 18
use this:
BigDecimal b = new BigDecimal(stringValue);
b = b.setScale(0,BigDecimal.ROUND_HALF_UP);
int i = b.intValue();
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

------------------
Miftah Khan
- Sun Certified Programmer for the Java� 2 Platform
- Sun Certified Web Component Developer for the Java� 2 Platform, Enterprise Edition
 
sachin shinde
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello friends,
Thanks for ur reply
I got output which is given by 'Miftah Khan'
I won't tried option given by anothers sorry for that but it's urgent so i was unable to do that one.
Now i will try for other options
Once again thanks for reply.
sachin
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!