Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
Solved

# Double.parseDouble Difficulties

Posted on 2000-04-11
Medium Priority
333 Views
I am using:

public void setUnits(String strUnits) {
try {
units = Double.parseDouble(strUnits);
}

to convert a string contaiing a number into a double value. In the above example, units is a double.

When I run this with a string value of 2330.693064, units is assigned 2330.69 but if I input 104.797350, units is assigned 104.797. If I input 10279.169841, units is asisgned 10279.2.

This seems to suggest that the precision is determined by the number of digits in the integer value.

I want to retain the six decimal places of my source value - is there a better way to convert the string value into a double?

harry.willis##sssltd.co.uk
(where ## is @)
0
Question by:harrywillis
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• Learn & ask questions
• 2

LVL 5

Accepted Solution

msmolyak earned 75 total points
ID: 2703898
Well, i've compiled a simple program

public class DoubleTest
{
public static void main(String[] args)
{
System.out.println(Double.parseDouble(args[0]));
}
}

and run it under JDK 1.2.2.  It seems to retain all the significant digits in the number you enter.

Why do you thing the numbers get truncated (or rounded)?

Michael
0

Author Comment

ID: 2703988
Using the debugger. Maybe it is just the debugger that is truncating / rounding....

I will try and add the value to my database and see what it stores.
0

Author Comment

ID: 2704194
Damn. The debugger in JBuilder (JB3 Enterprise Edition) was showing the truncated / rounded value.

Using System.out.prinln I found that the values were actually correct.

Thanks for your help msmolyak
0

## Featured Post

Question has a verified solution.

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

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correctâ€¦
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arrâ€¦
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 Month10 days, 11 hours left to enroll

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

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