Re: Big numbers
- From: jameskuyper <jameskuyper@xxxxxxxxxxx>
- Date: Tue, 13 Jan 2009 11:40:21 -0800 (PST)
marc wrote:
On 13 jan, 19:54, "Joachim Schmitz" <nospam.j...@xxxxxxxxxxxxxxxxxx>
wrote:
The question is not (primarily) how it is stored in the DB, but how you get
it out of that DB.
My problem is how to store it in C.
It's not important that it comes from a database.
You're correct. Where it comes from is unimportant. However, what form
it's stored in after the database query is very important, because the
correct way to print it depends upon what form it arrives in.
let's say I have :
unsigned long long u = 33748440199875750.25;
You're initializing 'u' with a floating point constant. That constant
has, by default, a type of 'double', which on most machines has
insufficient precision to hold all of the significant digits in that
number, which means it doesn't actually represent the value it appears
to represent. The best it can do is represent a 'double' value that is
as close as possible to the one specified, and that's not sufficiently
close to keep the last three digits accurate.
You could avoid that problem by adding an L to the end of the
constant, which would force it to have the type "long double", which
often will have sufficient precision. However, even if you do that,
the digits after the decimal place would still be lost as soon as you
store it in an object of type unsigned long long int, because (as
implied by the 'int'), such a type can only store integers, it can't
store the fractional part of that number.
It is extremely unlikely that your data base query returns it's
results in the form of a numeric literal in your source code. That
would imply that query generates the source code for your program,
which you recompile and run after each query. If that's not how the
results of your query are stored in your program, then you need to
tell us how they are actually stored.
.
- Follow-Ups:
- Re: Big numbers
- From: Flash Gordon
- Re: Big numbers
- References:
- Big numbers
- From: marc
- Re: Big numbers
- From: J. J. Farrell
- Re: Big numbers
- From: marc
- Re: Big numbers
- From: Joachim Schmitz
- Re: Big numbers
- From: marc
- Big numbers
- Prev by Date: Re: large array?? how to avoid stack overflow?
- Next by Date: Re: C vs. C++
- Previous by thread: Re: Big numbers
- Next by thread: Re: Big numbers
- Index(es):
Relevant Pages
|