0

I know that if you do

printf("Number: %.2f", 1.2345);

The result will be "1.23"

But i'm doing a calculator of big number's, for this project I separe the number in nodes Like (exemple) 123456789 [ 1 ] [ 2345 ] [ 6789 ]

and when I the number is: 100056789 for example I have [ 1 ] [ 0005 ] [ 6789 ]

But when I print I get [ 1 ] [ 5 ] [ 6789 ]

There is a method to see the other 0's before the comma whithout transfer all to a string? like "0005" (string) and print the string? There is a better way of doing that?

John Kugelman
  • 349,597
  • 67
  • 533
  • 578
  • 2
    Try %04d but it will not work if you have variable length numbers. It will only work if the numbers always have 9 digits. – cup May 13 '23 at 05:46
  • 1
    Representing big numbers in base-10 is not very compute-efficient. Usually, we want to use a power of 2 that fits in some number of bytes that is also a power of 2 (8, 16, 32, 64 bits). Then, the math happens in base-2 and you convert the result to base-10 for display. It can be a fallacy to design your internal data representation primarily for convenience of I/O. Not always, but usually. – paddy May 13 '23 at 05:53
  • I guess this is a duplicate : https://stackoverflow.com/questions/153890/printing-leading-0s-in-c#153895 – Damien May 13 '23 at 05:58
  • Agreed @paddy, but bignum FP representations for an interactive application may just be one of those things where it makes sense to design around I/O. I have written an implementation of formatting binary bignums as decimal FP, and I can assure you that it is complex and difficult to do correctly. – John Bollinger May 13 '23 at 12:46
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community May 16 '23 at 01:22

0 Answers0