Solved

format double

Posted on 2006-06-27
3
257 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

ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

Question has a verified solution.

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

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…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

823 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