How to convert ascii too.... int64, unsigned long..

Y

yekasi

Hi,

I have this number, 1.5283632704970307 in char*, and I need to convert
it to a double type in C++ that is capable of storing that number of
precisions.... I tried doing atof and storing it to a double type. it
came back with 6 digits precision only.

I also have this number, 1159964886109, in char*, and I need to convert
it to uint64... i did a atol, it converted it to a 2147483647, which
truncated 4 bytes for me...

Thank you in advance.

T
 
H

hoemke

Hi,

I have this number, 1.5283632704970307 in char*, and I need to convert
it to a double type in C++ that is capable of storing that number of
precisions.... I tried doing atof and storing it to a double type. it
came back with 6 digits precision only.

I also have this number, 1159964886109, in char*, and I need to convert
it to uint64... i did a atol, it converted it to a 2147483647, which
truncated 4 bytes for me...

Thank you in advance.

T

Try std::istringstream ...
 
V

Victor Bazarov

I have this number, 1.5283632704970307 in char*, and I need to convert
it to a double type in C++ that is capable of storing that number of
precisions.... I tried doing atof and storing it to a double type. it
came back with 6 digits precision only.

How do you know? What did you do to find that out?
I also have this number, 1159964886109, in char*, and I need to
convert it to uint64... i did a atol, it converted it to a
2147483647, which truncated 4 bytes for me...

There is no 'uint64' in C++. It's most likely a language extension
provided by your compiler. You need to look in the compiler manual or
ask in the newsgroup dedicated to your compiler to find out what to
use to convert a string into 'uint64'. Perhaps a special format
specifier in 'sscanf' would help?

V
 
K

Kai-Uwe Bux

Hi,

I have this number, 1.5283632704970307 in char*, and I need to convert
it to a double type in C++ that is capable of storing that number of
precisions.... I tried doing atof and storing it to a double type. it
came back with 6 digits precision only.

How did you determine that? Did you print out the double as in

std::cout << some_double << '\n';

Well, then you only see six digits of precision because that is the default
precision for output streams. Use std::setprecision() to make more digits
visible.
I also have this number, 1159964886109, in char*, and I need to convert
it to uint64... i did a atol, it converted it to a 2147483647, which
truncated 4 bytes for me...

There is no uint64 in standard C++ (as far as I know).


Best

Kai-Uwe Bux
 
T

tak

How did you determine that? Did you print out the double as in
std::cout << some_double << '\n';

Well, then you only see six digits of precision because that is the default
precision for output streams. Use std::setprecision() to make more digits
visible.

I see. Yes, thats what I did. when I do setprecision, i do get more
digits.
There is no uint64 in standard C++ (as far as I know).

if that is the case, what datatype will hold that many digits in C++
(12 bytes). And what function do i use to convert char* to "that" type?

thanks,
T
 
V

Victor Bazarov

tak said:
[no uint64 in standard C++]

if that is the case, what datatype will hold that many digits in C++
(12 bytes).

'double' usually fits that requirement. It has 16 digits of precision.
And what function do i use to convert char* to "that"
type?

There are strtod, sscanf, istringstream. You pick.

V
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top