JetJack
JetJack

Reputation: 988

How to round off the float values

Table1

Id value

001 2.3
002 1.3
003 3
004 5.3
...
...

value column datatype is float

Note:

value column will be .3 always, it will not come like .1, .2, .4, .5 to .9

Now i want to display .5 instead of .3 for all the values...

Expected Output

Id value

001 2.5 
002 1.5
003 3
004 5.5
...
...

How to make a query for this.

Need SQL Query Help

Upvotes: 0

Views: 2860

Answers (2)

praveen
praveen

Reputation: 12291

Use Round function to get your result

 Declare @Sample Table
 (ID int ,
 value float)

 Insert into @Sample
 values
(001,2.3),(002,1.4),(003,3),(004,5.3)

 Select ID,round(value/5,1)*5 from @Sample

If the value is greater than .3 then it will be rounded to .5 and if it is less than .3 then the integer value will be retrieved

Upvotes: 2

Chetter Hummin
Chetter Hummin

Reputation: 6837

You can use the floor function to figure out whether there is a decimal component

Please try the following query

update table1 set value = value + 0.2 
where value > floor(value);

Upvotes: 0

Related Questions