JM4
JM4

Reputation: 6788

Possible to round down to second decimal place based off 3+ decimal spots in MySQL

I am trying to figure out how to essentially create a "floor" call based on a specific decimal place as opposed to a whole value. Below is a table of actual values and the desired result:

=========|=========
3.125    |  3.12
4.187    |  4.18
1.212    |  1.21
5.999    |  5.99

Is this possible with mysql? using the round function to the 2nd decimal place returns "bad" data and rounding to the third does not reach the goal either.

Upvotes: 0

Views: 1043

Answers (2)

OMG Ponies
OMG Ponies

Reputation: 332661

Use the TRUNCATE function:

SELECT TRUNCATE(3.125, 2)

Output:

 3.12

Upvotes: 4

MrTippet
MrTippet

Reputation: 306

Could you multiply by 100 and floor and then divide by 100? Like

floor(value*100)/100

Upvotes: 1

Related Questions