Hi @Chirag Sitapara , Welcome to Microsoft Q&A,
You can check out the tutorial "During calculations, you need to use (decimal)
casts in equations to preserve the decimal part."
A common method is to use the Math.Round () function. This function rounds a Decimal type variable to a specified number of decimal places. For example, use Math.Round (d, 2) to preserve a Decimal type variable d to two decimal places.
You can also use Decimal.Round().
double originalValue = 3.14159;
decimal roundedValue = (decimal)originalValue; // Forced type conversion
roundedValue = Decimal.Round(roundedValue, 1); // Set the precision to 1 decimal place
Console.WriteLine(roundedValue);
Best Regards,
Jiale
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.