?
Solved

float type

Posted on 2006-04-19
7
Medium Priority
?
178 Views
Last Modified: 2010-03-31
I have a float variable . I dont want it showing on screen like : 2.34125E7 . I want it showing like : 23412500 . Which function can I use ?
0
Comment
Question by:tunhien
7 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 600 total points
ID: 16492156
You need to format it

System.out.printf("%.0f\n", f);
0
 
LVL 14

Assisted Solution

by:StillUnAware
StillUnAware earned 150 total points
ID: 16492157
simply do that:
 long l = (long)(f * 10000000);

and if You want the point showed, then since java 1.5 use this:

  String s = String.format("%.7f", floatvar);
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 16492175
or you can save it into a String:

String s = String.format("%.0f", f);
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 14

Expert Comment

by:StillUnAware
ID: 16492198
Sorry, I missed something here, CEHJ is right.
0
 

Author Comment

by:tunhien
ID: 16492200
7f ? 0f ? What does it mean ?
0
 
LVL 14

Expert Comment

by:Tommy Braas
ID: 16492298
Use

float myNumber = 23412500.0;
DecimalFormat df = new DecimalFormat("#,###.00");
System.out.println(df.format(myNumber));
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 16492343
:-)
0

Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Suggested Courses
Course of the Month9 days, 8 hours left to enroll

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question