For example, the SQL query returns the amount (money) - 67889.87, i.e. 67889 rubles and 87 kopecks. To get the whole part, easy - use the floor :

 select value, floor(value) from table t where t.id = ... 

How to get the fractional part as a whole, to return 87?

  • 3
    Maybe (field * 100)% 100 or say (field-floor) * 100 - Mike
  • and if the number = 10.001 what result do you expect to get? 1) 001, 2) 1 - Vanya Avchyan
  • @VanyaAvchyan there is a penny, .001 can not be (in theory), I expect to receive 1. - Denis
  • @Mike thought there was a function that would immediately give the right one. As an option, there is still round(mod(value, 1) * 100) . Post your comment as an answer? - Denis

1 answer 1

There are no special functions for obtaining the decimal fractional part, as a whole in MySQL. You can use, for example:

 select (value*100)%100 или select (value-floor(value))*100 
  • Do not tell 86.000000324 why there is an error, and without round displays 86.000000324 ? - Denis
  • one
    @Denis It’s probably in the float type that it looks like the usual error for this type - Mike