Re: Printf problem with big numbers....



On 2006-01-24, pasukaru@xxxxxxxxx <pasukaru@xxxxxxxxx> wrote:
> I need to work with big integers ( around 2.^64), and I know it is not
> possible to have integer that big.
> So I use "double" instead, and it is ok with calculations.
> But when I want to print them on screen or in a file, there is a
> problem...
>
> For example, if I write this :
>
> printf("result: %lf\n",1234567890987654321.012345678);
>
> What I get on cmd is:
>
> result: 1234567890987654400.000000

try %.0f to get rid of the extra decimal digits

[incidentally, %lf is not needed for printf, and is forbidden in c89]

> Can anybody tell me WHY ?

your doubles aren't precise enough? try long double maybe [though that's
not guaranteed to be better]
.



Relevant Pages

  • Re: Variable type Money/Currency
    ... By default, doubles cannot be ... > Do I need to take all my calculations and multiply them by 100? ... Prev by Date: ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: C sucks at math? (help)
    ... I said I wouldn't try doubles in the real project, ... do similar calculations in a much bigger project and the problem I'm ... the floating point hardware or emulation does. ...
    (comp.lang.c)
  • Re: Java rounding with big Decimal.
    ... That is, more or less, what I meant by "inherently inaccurate". ... less error in calculations involving them than you might with ... I still say BigDecimals are better than doubles, ...
    (comp.lang.java.programmer)
  • Re: Advantage of using byte over Long Integer?
    ... J P Hill wrote: ... > I'm using an Access DB to do a series of calculations. ... > data are stored as doubles to maximise accuracy. ...
    (microsoft.public.access.tablesdbdesign)
  • Re: double discrepancy between PDA and PC
    ... whatever you use from Math class uses doubles and that might ... calculations, ... the card reader takes electrical measurements off the pins with respect ... depending on the sensor and those are the values I use to do my ...
    (microsoft.public.dotnet.framework)