i want to print number after decimal point.Is there any way to do it e.g This is a decimal number 6.28 and i want to print .28.can any help me out with a simple example
extemer
-17
Junior Poster
Banned
Recommended Answers
Jump to PostThe following code could be helpful.
public class Prinf{ static double decimal(double d){ int dd = (int)d; d -=dd; return d; } public static void main(String args[]){ double d = 6.328941; System.out.printf("%8.6f\n",decimal(d)); } }
output:
0.328941
Jump to PostThe following code shows an idea on how to have only the figures after the decimal point are printed after the integer part is removed. Please rewording my comments if it is necessary.
public class Prinf{ static double decimal(double d){ //a method to return the value after …
Jump to PostYou can also do it another way, if you want to :)
First you make a String variable that holds the value of the double variable you are working with. You do this by using the method Double.toString() and the parameter you put in can either be the value …
Jump to PostAll I can say is, don't put that in your resume.
All 15 Replies
tong1
22
Posting Whiz
NormR1
563
Posting Sage
Team Colleague
tong1
22
Posting Whiz
mvmalderen
commented:
Good approach, I'd also have done this. :)
+8
NormR1
563
Posting Sage
Team Colleague
sneaker
25
Junior Poster in Training
Team Colleague
coil
commented:
good solution, well explained.
+1
extemer
-17
Junior Poster
Banned
jon.kiparsky
326
Posting Virtuoso
extemer
-17
Junior Poster
Banned
jon.kiparsky
326
Posting Virtuoso
extemer
-17
Junior Poster
Banned
jon.kiparsky
326
Posting Virtuoso
Ezzaral
commented:
Definitely.
+14
extemer
-17
Junior Poster
Banned
jon.kiparsky
326
Posting Virtuoso
extemer
-17
Junior Poster
Banned
Ezzaral
commented:
The code was awful. Stop having a tantrum.
-3
extemer
-17
Junior Poster
Banned
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.