sunleo
sunleo

Reputation: 10943

Decimal to Integer in sql

Remove the Decimal values

select cast(val as integer),val from table

and I tried round that is also not working pls tell me the way to solve this.

select ROUND(2.9,0) from dual

24  23.8331134259259
31  30.8322222222222
31  30.8321990740741
31  31.1120023148148
31  31.1119791666667
28  28.0590046296296
31  31.1177314814815
4   4.05344907407407
4   4.03957175925926
14  13.7137731481481
5   4.79490740740741
5   4.79490740740741
5   4.79489583333333
5   4.79488425925926

Expected Output :

23  23.8331134259259
30  30.8322222222222
30  30.8321990740741
30  31.1120023148148
30  31.1119791666667
28  28.0590046296296
31  31.1177314814815
4   4.05344907407407
4   4.03957175925926
13  13.7137731481481
4   4.79490740740741
4   4.79490740740741
4   4.79489583333333
4   4.79488425925926

Upvotes: 4

Views: 8582

Answers (3)

Noam
Noam

Reputation: 3391

Just select FLOOR(2.9,0) from dual

Upvotes: 1

Damien_The_Unbeliever
Damien_The_Unbeliever

Reputation: 239646

Are you looking for FLOOR?

FLOOR returns the largest integer equal to or less than n. The number n can always be written as the sum of an integer k and a positive fraction f such that 0 <= f < 1 and n = k + f. The value of FLOOR is the integer k. Thus, the value of FLOOR is n itself if and only if n is precisely an integer.

Upvotes: 3

Raphael
Raphael

Reputation: 1687

Hi try truncate function

TRUNC( number, [ decimal_places ] )

Upvotes: 5

Related Questions