Skip to content

Instantly share code, notes, and snippets.

@seolys
Last active July 28, 2021 06:09
Show Gist options
  • Save seolys/a8a9ca49604b7cfe468a512ac8ace255 to your computer and use it in GitHub Desktop.
Save seolys/a8a9ca49604b7cfe468a512ac8ace255 to your computer and use it in GitHub Desktop.
MySQL 소수점 올림, 버림, 반올림
/* MySQL 소수점 올림, 버림, 반올림 */
select ceil(10001.0001 / 1000) * 1000 as '11000' /* roundup(number, -3) */
, ceil(10001.0001 / 100) * 100 as '10100' /* roundup(number, -2) */
, ceil(10001.0001 / 10) * 10 as '10010' /* roundup(number, -1) */
, ceil(10001.0001 / 1) * 1 as '10002' /* roundup(number, 0) */
, ceil(10001.0001 / 0.1) * 0.1 as '10001.1' /* roundup(number, 1) */
, ceil(10001.0001 / 0.01) * 0.01 as '10001.01' /* roundup(number, 2) */
, ceil(10001.0001 / 0.001) * 0.001 as '10001.001' /* roundup(number, 3) */
, truncate(99999.9999, -3) as '99000' /* rounddown(number, -3) */
, truncate(99999.9999, -2) as '99900' /* rounddown(number, -2) */
, truncate(99999.9999, -1) as '99990' /* rounddown(number, -1) */
, truncate(99999.9999, 0) as '99999' /* rounddown(number, 0) */
, truncate(99999.9999, 1) as '99999.9' /* rounddown(number, 1) */
, truncate(99999.9999, 2) as '99999.99' /* rounddown(number, 2) */
, truncate(99999.9999, 3) as '99999.999' /* rounddown(number, 3) */
, round(55555.5555, -3) as '56000'
, round(55555.5555, -2) as '55600'
, round(55555.5555, -1) as '55560'
, round(55555.5555, 0) as '55556'
, round(55555.5555, 1) as '55555.6'
, round(55555.5555, 2) as '55555.56'
, round(55555.5555, 3) as '55555.556'
from dual
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment