There are 3 ways to round off decimal to two decimal places :
1. Use ToString()
double d = 2.445;
d.ToString("0.00")
Output : 2.45
2. Use Math.Round
double d = 2.445;
Math.Round(d, 2)
Output : 2.44
3. Create a Custom logic method like below :
N = 2.445 I want to show "2.45" only.
Step a. N*100 + 0.5 = 245
Step b. Divide System.Math.Floor(245) by 100
Step c. The result will be 2.45
Subscribe to:
Post Comments (Atom)
Popular Posts
-
Answer : WCF belongs to System.ServiceModel
-
Different types of assemblies are : Static and Dynamic assemblies Private and Shared assemblies Single file and Multiple file assemblies ...
-
Authorization is used to determine whether user has access to resource or not. There are two ways to authorize a resource : File authoriza...
-
Operation behaviour are scoped at Operation level. It is used for transaction flow , serialization , parameter handling.
-
Different type of method parameters in C# are : Value Parameter Reference Parameter Output Parameter
-
Abstract class has following features : cannot be instantiated contain abstact methods and properties cannot modify abstract class with s...
-
OOPs concepts that C# supports are : Abstraction : is a process that involves identifying the crucial behavior of an object and eliminatin...
-
Characteristics of well designed normalized database are : Table should have identifier Table should store data for single type of entity...
-
There are five types of contracts : Service Contract Operation Contract Data Contract Message Contract Fault Contract Please refer be...
No comments:
Post a Comment