Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR SQL

select mysql limit to 2 decimal places

/**
When formatting number to 2 decimal places you have two options TRUNCATE and ROUND.
You are looking for TRUNCATE function.
Examples:
**/

-- Without rounding:
TRUNCATE(0.166, 2)
-- will be evaluated to 0.16

TRUNCATE(0.164, 2)
-- will be evaluated to 0.16
-- docs: http://www.w3resource.com/mysql/mathematical-functions/mysql-truncate-function.php

-- With rounding:
ROUND(0.166, 2)
-- will be evaluated to 0.17

ROUND(0.164, 2)
-- will be evaluated to 0.16
-- docs: http://www.w3resource.com/mysql/mathematical-functions/mysql-round-function.php
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #select #mysql #limit #decimal #places
ADD COMMENT
Topic
Name
3+1 =