skip to Main Content

how can I store large decimal values in MYSQL?

I have tried to use the decimal(10,9) but the value ends up being transformed to: 99999999.99

Example: 2110624448.26533720

Expected save value: 2110624448.26533720

Thanks in advance

2

Answers


  1. To store the value 2110624448.26533720 without any loss of precision, you need to adjust the precision and scale of your DECIMAL column.

    For example, if you want to store values with up to 8 digits to the left of the . and 8 digits to the right of the ., you can define your column as DECIMAL(16, 8):

    CREATE TABLE your_table_name (
        your_decimal_column DECIMAL(16, 8)
    );
    

    This will allow you to store values like 2110624448.26533720 without any rounding.

    Login or Signup to reply.
  2. In your case, you want to store a value like 2110624448.26533720 which has a precision of 10 and a scale of 8

    CREATE TABLE table (column DECIMAL(18, 8));
    

    DECIMAL(18, 8) specifies a total of 18 digits (including both integer and decimal parts) and 8 decimal places.

    If you’ve already created the table, use the ALTER TABLE statement to modify the column:

    ALTER TABLE table MODIFY column DECIMAL(18, 8);
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search