non-floating point 12-digit datatype?

Started by
19 comments, last by Michalson 18 years, 5 months ago
I'm just looking for something that can store a 12-digit barcode. Long double stores enough digits, but when it's output it's in scientific notation. Do I need to make my own datatype? Thanks.
Advertisement
Which programming language are you using, and what compiler? If this was VB I'd recommend giving the Currency type a try.
Oh, sorry, forgot to say it's C++. I'm using the mingw32 compiler (dev-cpp).
I believe long long will just barely give you enough room. It should be 64 bits under MinGW.
all right.
Quote:Original post by SiCrane
I believe long long will just barely give you enough room. It should be 64 bits under MinGW.
Actually, 64-bits is enough for 19 decimal digits.
Erp. For some reason I was thinkg BCD numbers not normal binary numbers.
Okay, I did that and I'll type in a 12-digit number like 849569346323 and I initially read it in as a string, so when I use atoi() to change it back to a long long, I get some weird 10-digit number like 1465340171. Is this a problem with atoi()? Should I use a different function to convert from std::string to long long?
atoi() only works for ints; for long long, I believe you can use boost::lexical_cast or stringstreams to get proper values.
Quote:Original post by sarbruis
Okay, I did that and I'll type in a 12-digit number like 849569346323 and I initially read it in as a string, so when I use atoi() to change it back to a long long, I get some weird 10-digit number like 1465340171. Is this a problem with atoi()? Should I use a different function to convert from std::string to long long?
I think GCC implements an equivalent atoll() function for 64-bit integers.

This topic is closed to new replies.

Advertisement