Solved

format double

Posted on 2006-06-27
3
271 Views
Last Modified: 2010-04-24
currently im converting a Standard::String to a double - this is the code im using

retArray[i] = System::Convert::ToDouble(strArray[i]);

as you can see, i have two arrays, one of doubles, the other of strings.

now it goes fine -  except for example i have a string value of "0.70", after the conversion the value in the double array is 0.699999999

shouldnt be that big of a deal, but im doing a number of iterations after that value is obtained, and i want it to be exact.

any idea how to get the value in after its passed to be 0.700000000????

thanks in advance

~b
0
Comment
Question by:bramsquad
3 Comments
 
LVL 30

Assisted Solution

by:Axter
Axter earned 62 total points
ID: 16997168
Hi bramsquad,
> any idea how to get the value in after its passed to be 0.700000000????
A double is not an exact number.
If you need higher precission, you need to use a different type.

Cheers!
0
 
LVL 8

Author Comment

by:bramsquad
ID: 16997352
thanks axter,

different type like what?

~b
0
 
LVL 15

Accepted Solution

by:
lakshman_ce earned 63 total points
ID: 16998026
Try to get the object's value using

Object* defaultValue== __box( Convert::ToDouble( strArray[i]) );

check value here

retArray[i] = *dynamic_cast<__box Double*>(obj);

Also you can use the IFormatProvider class to change the formatting.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Create mosaic from photograph 9 160
VB Email Check 2 260
Get the height value of a parent form 2 190
please insert disk adobe master collection6 9 1,522
The following diagram presents a diamond class hierarchy: As depicted, diamond inheritance denotes when two classes (e.g., CDerived1 and CDerived2), separately extending a common base class (e.g., CBase), are sub classed simultaneously by a fourt…
In Easy String Encryption Using CryptoAPI in C++ (http://www.experts-exchange.com/viewArticle.jsp?aid=1193) I described how to encrypt text and recommended that the encrypted text be stored as a series of hexadecimal digits -- because cyphertext may…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

726 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