Skip to main content
GameDev.net gamedev.net
🔒 Locked

Formatting Numbers in Java

Started by l jsym l Sep 20, 2009 at 7:51 PM 2 replies 700+ views
Original Post
l jsym l
l jsym l
hey, im making a program for my college course in JAVA and can't find anywhere in the texts books how to format a double to have 0 decimal places when i put it in a outfile. i know the "%.2f" command, which displays the number to 2 decimal places but i cant figure it out how to make it to just an integer...if anyone has anyidea at all PPPLLEEEAAASSE let me know thanks yoU! [Edited by - jpetrie on September 21, 2009 10:30:13 AM]
l jsym l
X Abstract X
X Abstract X
double myDouble = 6.79;int myInt = (int)myDouble;


This will just chop off the decimal, no rounding.
l jsym l
l jsym l
thanks! it works perfect!
l jsym l
snak_attack
snak_attack
For future reference (and more complex formats), use the DecimalFormat class

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.