Click here to Skip to main content
15,886,067 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi,

i had got issue regarding VB String to double conversion and C++ CString to double conversion.

i have a value in VB :

String -> 2.48365014976068

in VB they are using Val function while converting to double they are getting the same value in double as well i.e (2.48365014976068)


in C++:

String -> 2.48365014976068

in C++ while converting from CString to double the value in double is ( i.e 2.4836501497606802)

both vb and c++ giving different values ..please help me

What I have tried:

VB:
double d = Val(2.48365014976068)

C++:
double d = _tsof(2.48365014976068)
Posted
Updated 31-May-17 6:23am

1 solution

No, the values are both the same. It is only the string representation that is different. See What Every Computer Scientist Should Know About Floating-Point Arithmetic[^].
 
Share this answer
 
Comments
Maciej Los 31-May-17 14:14pm    
5ed!
Member 12677926 31-May-17 23:22pm    
string representation is fine i think .. could you please exaplain how it is wrong .as showing different values
Richard MacCutchan 1-Jun-17 4:28am    
Nothing is wrong. Floating point numbers can be displayed to any precision, within the ranges described at Data Type Ranges[^]. If you do not understand how floating point numbers work in computers then you should avoid using them and stick to integer or decimal types.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900