0

If I do

select 18000*13/100000

it returns 2

when it should return 2.34

How do I make it return the correct number?

thanks

Bill
  • 751
  • 2
  • 8
  • 18
  • `select 18000.0*13/100000` – Blorgbeard Sep 30 '15 at 19:44
  • Yeah you need to add a decimal point in there somewhere otherwise SQL will assume you want the result back as an integer. – ewahner Sep 30 '15 at 19:46
  • 1
    SQL server uses integer math that is, when working with whole numbers it will return only whole numbers, to get decimals you can use implicit casting such as is done by adding .0 to any number, or you can explicitly cast an integer to a numeric value with set decimals. using float you may get unexpected rounding errors due to the nature of FLOAT so depending on the context of the math, float may not be what your after. – xQbert Sep 30 '15 at 19:47

2 Answers2

1
select 18000*13/100000.0

Use a float either in numerator or denominator to get a float.

Vamsi Prabhala
  • 48,685
  • 4
  • 36
  • 58
1

Use a decimal point to avoid integer division:

select 18000.0*13/100000

You can also CAST() as DECIMAL or FLOAT a field, but I like to just use mycol *1.0

Hart CO
  • 34,064
  • 6
  • 48
  • 63