0

I want to store a number that contain 14 digits

when I store the number as a float for exemple I want to store this number : 12345678912345

the first 8 digit stored normaly and the other will be a garbeg like that: 12345679020032.000000

this is the number that i get in the result

this is the function tha store the first digit:

void enqueue_number(double button_clicked){
    if(numbers_isFull()) 
        return;
    if (numbers_isEmpty()){ 
        front = rear = 0; 
    }
    else{
        rear = (rear+1)%MAX_SIZE;
    }
    numbers[rear] = button_clicked;
}

and this is the function that store the other digits:

void update_number(int button_clicked){
    if(rear == -1)
        return;
    numbers[rear] = (numbers[rear] * 10) + button_clicked;
}
  • Are you using the `float` which doesn't hold the digits (as you've shown), or are you using `double` as given for function argument? Or are you flipping between `float` and `double`? – Weather Vane Jul 31 '22 at 19:01
  • A `float` only holds about 7 digits of precision, so this is not suprising. Is there a question here? If you want to store 14 digits, store 14 digits. – Chris Dodd Jul 31 '22 at 19:04
  • 1
    If "a number that contain 14 digits" is an integer, then use a 64-bit integer. – Weather Vane Jul 31 '22 at 19:05
  • 1
    If a `long long` or a `long double` is not sufficient for representing the number, then you may want to consider using a [bignum library](https://en.wikipedia.org/wiki/List_of_arbitrary-precision_arithmetic_software), such as [GMP](https://en.wikipedia.org/wiki/GNU_Multiple_Precision_Arithmetic_Library). Using such a library costs additional space and is slower, but you can have as much precision as you want. – Andreas Wenzel Jul 31 '22 at 19:05
  • @WeatherVane I'm using float – Hocine Abderrahmane Aug 07 '22 at 05:01
  • how can store 14 digit – Hocine Abderrahmane Aug 07 '22 at 05:02
  • 1
    You can use a 64-bit integer, or a `double` if the number is fractional, or a string. You haven't shown the use case: a number isn't always an integer. For example a phone number isn't an integer: it's a string of (usually) digits. – Weather Vane Aug 07 '22 at 07:41

0 Answers0