Data truncated for column when multiplying numbers

alexander7567

I am using the below query on the below data. However, when I do this I am getting the error "Data truncated for column 'strength' at row 1" for every column and row. I researched it a little, and as far as I can tell, most people are getting this error because they are trying to use text or char. I have never seen this warning before and I am getting the expected results, but with 4,700 warnings.

UPDATE userstats 
    SET strength = (strength * .999), 
        agility = (agility * .999), 
        guard = (guard * .999), 
        labour = (labour * .999), 
        IQ = (IQ * .999) 
WHERE gym_train_since_cron = 0

Database columns Database rows

Any help would be greatly appreciated!

Jonathon Ogden

strength * .999 is resulting in a number with more than 4 decimal places. That goes for all of these calculations.

To avoid the warnings, you can either ROUND or TRUNCATE the result of the calculation. For example: SET strength = ROUND(strength * .999, 4) or SET strength = TRUNCATE(strength * .999, 4).

You may wonder what the difference between the two functions are; it's the rounding behavior. For TRUNCATE it will round a number towards 0, whereas ROUND, depending on the numeric data type (exact or approximate) which in your case is decimal (an exact type), the following occurs (taken from Rounding Behavior):

For exact-value numbers, ROUND() uses the “round half up” rule: A value with a fractional part of .5 or greater is rounded up to the next integer if positive or down to the next integer if negative. (In other words, it is rounded away from zero.) A value with a fractional part less than .5 is rounded down to the next integer if positive or up to the next integer if negative.

To demonstrate, here's an example using the strength value for user 4898 from your sample data:

strength * .999 = 16331143.7521566 -- Over 4 decimal places, hence the warning
ROUND(strength * .999, 4) = 16331143.7522 -- Rounds up
TRUNCATE(strength * .999, 4) = 16331143.7521 -- Rounds down

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Error Code: 1265. Data truncated for column

Data truncated for column?

Laravel: String data, right truncated: 1406 Data too long for column

Why is my data being truncated? Warning | 1265 | Data truncated for column

Algorithm for multiplying two numbers

Data truncated for column

How to avoid underflow when multiplying real numbers?

SQLSTATE[01000]: Warning: 1265 Data truncated for column

multiplying column

MYSQL Truncated incorrect DOUBLE value: Upon multiplying

SequelizeDatabaseError Data truncated for column position at row 4

Mariadb 10.4 Data truncated for column 'column_name' on insert but not on update

Laravel string data, right truncated: 1406 Data too long for column

MYSQL: Data truncated for column 'mtf' at row 1

Multiplying column means for groups by column mean for the entire data

R: Multiplying One Column to the Rest of the Data Frame Based on Index/Position

Multiplying big numbers in Haskell

How to solve Data truncated for column issue

Convert row to column when data are not numbers

Multiplying elements of a matrix depending on numbers and strings of the row names and column names

I get the following error when import CSV to a table in Heidi SQL "SQL Error: Data truncated for column 'SlNo' at row 1"

Multiplying array numbers sequentially

Last Zeros Truncated When Getting External Data

Multiplying values in a column of data frame based on the numbers found in other column

MYSQL: 1265 Data truncated for column?

ERROR 1265 (01000): Data truncated for column

Multiplying elements of one column with all elements from another data set

Data from Sybase image column truncated at 32 KiB when retrieved via pyodbc

What is the behaviour of xarray when multiplying data arrays?