[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
• Status: Solved
• Priority: Medium
• Security: Public
• Views: 246

# Using a SQL Statement, I need to format a division result to 4 digits after the decimal point.

Using a SQL Statement, I need to format a division result to 4 digits after the decimal point.

Example:

SELECT X, Y, X/Y As Ratio FROM Filename
X and Y are stored as Real.

X=40.12345678, Y=38.2727272

Query returns 1 for X/Y

Should return 1.048

What expression should I use ?
0
Dovberman
• 2
• 2
1 Solution

Billing EngineerCommented:
real? you should use decimal(20,8) instead, for example.

SELECT X, Y, cast(X as decimal(20,8)) / cast(Y as decimal(20,8)) As Ratio FROM Filename
0

Author Commented:
My mistake. I was using X/X instead of X/Y.

Results are now

1.075179
1.103112
1.054205
1.106358
1.038615

I would still like to round results only to 4 decimal places.

Thanks,
0

Author Commented:
What expression would round the results to 4 decimal places.
0

Billing EngineerCommented:

SELECT X, Y, cast( X / Y  as decimal(20,4)) As Ratio FROM Filename
0

## Featured Post

• 2
• 2
Tackle projects and never again get stuck behind a technical roadblock.