Mysql how to select value front of decimal

I'am a newbie.. I'm sorry if my question is repost.. i want to ask how to get value front of decimal on mysql..

here my fiddle example

i try to use FORMAT on mysql

`SELECT FORMAT(desc,0) FROM table1`

the result is round.. in my case i dont want the result rounded.

i want the result is

1. 9
2. 9
3. 11
4. 11

sorry if i'm wrong.. thanks for help..

Upvotes: 1

Views: 226

Answers (4)

Hanky Panky
Hanky Panky

Reputation: 46900

FLOOR it.

SELECT id, FLOOR(desc) FROM table1

This will remove the decimal places and return that whole number which you are looking for.

Result

  1. 9
  2. 9
  3. 11
  4. 11

Fiddle

Upvotes: 2

Ramesh
Ramesh

Reputation: 1942

You can Use FLOOR()

select  id,FLOOR(decs) from table1 

SQL FIDDLE

SEE HERE

Upvotes: 2

Joshua Fabillar
Joshua Fabillar

Reputation: 496

use round().. get all the data from your sql database then loop it

for example you have

$number = "1.00";

or

$number = 1.00;

then use round()

echo round($number);

the output is 1

Upvotes: 0

vhadalgi
vhadalgi

Reputation: 7189

you can also use ROUND to truncate decimal places

SELECT ROUND(@column_name,0,1)

OR

example select CAST(Round(MySum * 20.0 /100, 0) AS INT)

91 * 20 / 100 => 1820 / 100 => 18 (truncated from 18.20)

Upvotes: 0

Related Questions