« ROUND() :: MySQL Function of the Day | Main | MySQL Pop Quiz #25 »
TRUNCATE :: MySQL Function of the Day
By Carsten | April 22, 2008
Function name: TRUNCATE
Aliases: -
Function type: Numerical function
Purpose: Round a number toward zero
Description: TRUNCATE() works almost, but not quite, like ROUND(), which was discussed yesterday. Firstly, the second parameter is never optional. Secondly, TRUNCATE() always rounds toward 0 and does so by chopping off decimals, without consideration as to what constitutes the “nearest” rounded number:
truncate(123.456, 2): 123.45
truncate(-123.456, 2): -123.45
just as for ROUND the second parameter may be negative::
truncate(123.456, -2): 100
truncate(-123.456, -2): -100
MySQL manual entry on TRUNCATE()
MySQL Function of the Day is a small series of concise information regarding most of the functions and operators available in MySQL. Inspired by PHPs funcaday, it’s meant to provide a daily dose of something in-between “Aha!” and “Ho-hum, I knew that already”, depending on your level of experience with MySQL. You can access the entire series with your browser here or pick up the RSS feed here.
Topics: MySQL Function of the day |