Results 1 to 19 of 19
Thread: Set number of significant digits
 08232013, 06:30 AM #1Member
 Join Date
 Jul 2013
 Posts
 52
 Rep Power
 0
Set number of significant digits
I have came across a problem where I have to display an output to a double to number of significant digits.
Eg: round to 3 significant digits
12345 > 12300
2.4134 > 2.14
I read through the Java document on Decimal Format but i could not found any way on reducing double to significant digits.
Is there any java built in on this?
DecimalFormat (Java Platform SE 7 )
 08232013, 07:19 AM #2Member
 Join Date
 Jul 2013
 Posts
 52
 Rep Power
 0
Re: Set number of significant digits
Isn't #.## is for formatting number of decimal places? it does not format number of significant digits.
 08232013, 07:39 AM #3
Re: Set number of significant digits
For formatting to display a specified number of significant digits, as far as I know there isn't anything for that in the standard JDK. You may be able to find a ready made solution in one of the many open source projects, and failing that would need to roll your own. I would probably go with scaling the number till I had the required number of digits to the left of the decimal point, converting that to an int value and then applying formatting rules for the scaling factor.
dbIf you're forever cleaning cobwebs, it's time to get rid of the spiders.
 08232013, 09:10 AM #4
 08232013, 10:26 AM #5
Re: Set number of significant digits
allaudin, don't delete content that has been responded to as that makes a forum thread difficult to follow for those who come later.
If your response was in error and is pointed out, it's best to edit the post and add a note to that effect.
dbIf you're forever cleaning cobwebs, it's time to get rid of the spiders.
 08232013, 10:48 AM #6
 Join Date
 Sep 2008
 Location
 Voorschoten, the Netherlands
 Posts
 14,051
 Blog Entries
 7
 Rep Power
 23
Re: Set number of significant digits
The only person who got everything done by Friday was Robinson Crusoe.
 08232013, 11:28 AM #7Just a guy
 Join Date
 Jun 2013
 Location
 Netherlands
 Posts
 5,063
 Rep Power
 8
Re: Set number of significant digits
Wagging finger: I did that too in the early years, only I just phrased myself differently; in stead of making it look I was answering, I was proposing a possible solution and asking for feedback on its correctness. I learned a great deal by being corrected that way. Its no good for your education to not post at all, IMO. Just make sure you show the proper intentions.
"Syntactic sugar causes cancer of the semicolon."  Alan Perlis
 08232013, 12:41 PM #8
 Join Date
 Sep 2008
 Location
 Voorschoten, the Netherlands
 Posts
 14,051
 Blog Entries
 7
 Rep Power
 23
Re: Set number of significant digits
I disagree; not only are repliers (who do know what they talking about) tempted to answer the OP but also correct the answer given by replier(s) who don't know what they're talking about.It obfusctes the original discussion in the thread. One can also learn by reading topics in the forum(s); there is no need to try to answer stuff one doesn't know about (yet).
kind regards,
JosThe only person who got everything done by Friday was Robinson Crusoe.
 08232013, 12:56 PM #9Just a guy
 Join Date
 Jun 2013
 Location
 Netherlands
 Posts
 5,063
 Rep Power
 8
Re: Set number of significant digits
We'll have to agree to disagree then :)
"Syntactic sugar causes cancer of the semicolon."  Alan Perlis
 08232013, 01:16 PM #10
 Join Date
 Sep 2008
 Location
 Voorschoten, the Netherlands
 Posts
 14,051
 Blog Entries
 7
 Rep Power
 23
Re: Set number of significant digits
Your mother was a hamster and your father smelt of elderberries; so there ...
kindest regards,
Jos ;)The only person who got everything done by Friday was Robinson Crusoe.
 08232013, 01:42 PM #11Just a guy
 Join Date
 Jun 2013
 Location
 Netherlands
 Posts
 5,063
 Rep Power
 8
 08232013, 02:34 PM #12
 Join Date
 Sep 2008
 Location
 Voorschoten, the Netherlands
 Posts
 14,051
 Blog Entries
 7
 Rep Power
 23
 08232013, 02:54 PM #13Just a guy
 Join Date
 Jun 2013
 Location
 Netherlands
 Posts
 5,063
 Rep Power
 8
 08232013, 04:00 PM #14
 Join Date
 Sep 2008
 Location
 Voorschoten, the Netherlands
 Posts
 14,051
 Blog Entries
 7
 Rep Power
 23
 08232013, 04:04 PM #15Just a guy
 Join Date
 Jun 2013
 Location
 Netherlands
 Posts
 5,063
 Rep Power
 8
Re: Set number of significant digits
Sorry. Fridaymischievousness.
"Syntactic sugar causes cancer of the semicolon."  Alan Perlis
 08232013, 04:14 PM #16
 Join Date
 Sep 2008
 Location
 Voorschoten, the Netherlands
 Posts
 14,051
 Blog Entries
 7
 Rep Power
 23
 08232013, 04:32 PM #17Just a guy
 Join Date
 Jun 2013
 Location
 Netherlands
 Posts
 5,063
 Rep Power
 8
Re: Set number of significant digits
What kind of effect would that have on my Fridaymischievousness? I'm a prick wherever I am.
"Syntactic sugar causes cancer of the semicolon."  Alan Perlis
 08232013, 05:17 PM #18
 Join Date
 Sep 2008
 Location
 Voorschoten, the Netherlands
 Posts
 14,051
 Blog Entries
 7
 Rep Power
 23
Re: Set number of significant digits
The only person who got everything done by Friday was Robinson Crusoe.
 08242013, 05:34 AM #19Member
 Join Date
 Jul 2013
 Posts
 52
 Rep Power
 0
Similar Threads

Telephone Number To Digits
By irnie1994 in forum JCreatorReplies: 1Last Post: 10072011, 04:15 PM 
need help with Number Pyramid with Double Digits
By SmellyFoot in forum New To JavaReplies: 5Last Post: 03292011, 12:04 PM 
Separating the digits of given number
By lb2 in forum New To JavaReplies: 5Last Post: 09092010, 05:29 AM 
Count number of digits in string using scanner
By wendysbiggy in forum New To JavaReplies: 35Last Post: 01202010, 06:11 AM 
rounding a double in a number of significant numbers
By rikribbers in forum Advanced JavaReplies: 2Last Post: 10272008, 04:35 PM
Bookmarks