• Status: Solved
• Priority: Medium
• Security: Public
• Views: 201

# Need this SQL rewritten in C#

I have this SQL :

UPDATE Nop_ProductVariant
SET Price =
CASE WHEN Price-floor(Price) >= 0.70 THEN floor(Price) + 0.95 ELSE
CASE WHEN Price-floor(Price) >= 0.50 THEN floor(Price) + 0.69 ELSE
CASE WHEN Price-floor(Price) >= 0.30 THEN floor(Price) + 0.49 ELSE
CASE WHEN Price-floor(Price) >= 0.01 THEN floor(Price) + 0.29  ELSE
CASE WHEN Price-floor(Price) = 0.00 THEN floor(Price) + 0.00
END END END END  END

It rounds the digits after the decimal point.

So if Price is "29.14", it would be "29.29", . . . "18.78" would be "18.99", etc.

I now need this written in C#. How can I do this?  thanks

0
MikeMCSD
• 2
1 Solution

Commented:
double price = 0;
if (price - System.Math.Floor(price) >= 0.7) {
price = System.Math.Floor(price) + 0.95;
} else if (price - System.Math.Floor(price) >= 0.5) {
price = System.Math.Floor(price) + 0.69;
} else if (price - System.Math.Floor(price) >= 0.3) {
price = System.Math.Floor(price) + 0.49;
} else if (price - System.Math.Floor(price) >= 0.01) {
price = System.Math.Floor(price) + 0.29;
} else if (price - System.Math.Floor(price) == 0.0) {
price = System.Math.Floor(price) + 0.0;
}
0

Commented:
actually no need to declare price (take this out double price=0)
this should be it
``````if (price - System.Math.Floor(price) >= 0.7) {
price = System.Math.Floor(price) + 0.95;
} else if (price - System.Math.Floor(price) >= 0.5) {
price = System.Math.Floor(price) + 0.69;
} else if (price - System.Math.Floor(price) >= 0.3) {
price = System.Math.Floor(price) + 0.49;
} else if (price - System.Math.Floor(price) >= 0.01) {
price = System.Math.Floor(price) + 0.29;
} else if (price - System.Math.Floor(price) == 0.0) {
price = System.Math.Floor(price) + 0.0;
}
``````
0

Author Commented:
Thank you
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.