0

I know there are different variations of this question asked. But what I am trying to do is that, there is a table with a numeric column (12,0) that has data looking like

Units
-----
-1222222
0
-19
21123021

What they really mean is this

Units
-----
-12222.22
0.00
-0.19
211230.21

With two decimal places in the last digits of each number.

I am struggling to convert these numbers to a two decimal place float column(Units)

2
  • Try units/100.00 Feb 20, 2020 at 18:39
  • @JoeDBA_HAHAHA Now i feel dumb...I was doing units/100 and kept getting an integer number. Thanks Feb 20, 2020 at 18:44

1 Answer 1

0

Something like this will do:

with data as 
(
select -1222222 as foo 
union
select 0
union 
select -19
union 
select 21123021
)
select cast(cast(foo as decimal)/100 as decimal(10,2))
from data;

You can also use format(foo,'N2') and a million other ways.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.