Solved

format double

Posted on 2006-06-27
3
229 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
Comment Utility
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
Comment Utility
thanks axter,

different type like what?

~b
0
 
LVL 15

Accepted Solution

by:
lakshman_ce earned 63 total points
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

771 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now