Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / February 2008

Tip: Looking for answers? Try searching our database.

double to string

Thread view: 
zamba - 04 Feb 2008 12:50 GMT
hi, i want to know how to convert a doble value like this 98.34 to
string 00009834  or 9.34 to 00000934 thanks a lot !!!!!
Florian Huebner - 04 Feb 2008 13:06 GMT
> hi, i want to know how to convert a doble value like this 98.34 to
> string 00009834  or 9.34 to 00000934 thanks a lot !!!!!

http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Double.html#toString()
zamba - 04 Feb 2008 13:51 GMT
> > hi, i want to know how to convert a doble value like this 98.34 to
> > string 00009834  or 9.34 to 00000934 thanks a lot !!!!!
>
> http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Double.html#toString()

thank you , but i read link and i tried to use NumberFormat , but i
can't get an example how to use exactly the way i need...
Florian Huebner - 04 Feb 2008 14:50 GMT
>>> hi, i want to know how to convert a doble value like this 98.34 to
>>> string 00009834  or 9.34 to 00000934 thanks a lot !!!!!
>> http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Double.html#toString()
>
> thank you , but i read link and i tried to use NumberFormat , but i
> can't get an example how to use exactly the way i need...

In that case I would just replace the "." with and empty string, count
the remaining letters and add as many zeros as you need.
John W. Kennedy - 05 Feb 2008 02:21 GMT
>>> hi, i want to know how to convert a doble value like this 98.34 to
>>> string 00009834  or 9.34 to 00000934 thanks a lot !!!!!
>> http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Double.html#toString()
>
> thank you , but i read link and i tried to use NumberFormat , but i
> can't get an example how to use exactly the way i need...

final DecimalFormat df = new DecimalFormat("00000000");
df.setMultiplier(100);
Signature

John W. Kennedy
If Bill Gates believes in "intelligent design", why can't he apply it to
Windows?

Tim Slattery - 04 Feb 2008 17:36 GMT
>hi, i want to know how to convert a doble value like this 98.34 to
>string 00009834  or 9.34 to 00000934 thanks a lot !!!!!

Check out the DecimalFormat class.

Signature

Tim Slattery
Slattery_T@bls.gov
http://members.cox.net/slatteryt

Andreas Leitgeb - 04 Feb 2008 18:57 GMT
>>hi, i want to know how to convert a doble value like this 98.34 to
>>string 00009834  or 9.34 to 00000934 thanks a lot !!!!!
> Check out the DecimalFormat class.

I guess, it would be easier, if he(zamba) first multiplied with
100, and then used some integral format.
John W. Kennedy - 05 Feb 2008 02:22 GMT
>>> hi, i want to know how to convert a doble value like this 98.34 to
>>> string 00009834  or 9.34 to 00000934 thanks a lot !!!!!
>> Check out the DecimalFormat class.
>
> I guess, it would be easier, if he(zamba) first multiplied with
> 100, and then used some integral format.

DecimalFormat.setMultiplier()

Signature

John W. Kennedy
A proud member of the reality-based community.

Hal Rosser - 05 Feb 2008 01:49 GMT
> hi, i want to know how to convert a doble value like this 98.34 to
> string 00009834  or 9.34 to 00000934 thanks a lot !!!!!

I think it goes something like this:

assume you have a double n with a value of 9.34 which you want to display as
009.34 string.
NumberFormat nf = NumberFormat.getNumberInstance();
//set the min digits before the decimal
nf.setMinimumIntegerDigits(3);
//set min digits after decimal
nf.setMinimumFractionalDigits(2);
String numberToShow = nf.format(n);
//numberToShow will be your string
Hal Rosser - 05 Feb 2008 02:02 GMT
>> hi, i want to know how to convert a doble value like this 98.34 to
>> string 00009834  or 9.34 to 00000934 thanks a lot !!!!!
[quoted text clipped - 10 lines]
> String numberToShow = nf.format(n);
> //numberToShow will be your string

But to follow up: You would not format 98.34 to display as  "00009834"
because then it would not be the same number.
Lew - 05 Feb 2008 02:58 GMT
>>> hi, i want to know how to convert a doble value like this 98.34 to
>>> string 00009834  or 9.34 to 00000934 thanks a lot !!!!!
[quoted text clipped - 12 lines]
> But to follow up: You would not format 98.34 to display as  "00009834"
> because then it would not be the same number.

How you format the number for display or storage has no effect on what the
number is.

Plenty of formats use implicit decimal points, so the OP would indeed have
"the same number" given the implicit location of the decimal point.

It is no more sensible to say the number is "not the same" than to say that
the European-format "9,834" does not represent the same number as the
American-format "9.834", or to claim that the European "9.834" does.

Signature

Lew



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.