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
-
Cache Callback provides an ability where by some actions can be performed when that item is removed from cache CacheItemRemovedCallback ex...
-
XML DOM loads the entire xml document into memory whereas Simple API for XML ( SAX ) does not load entire xml document into memory XML DOM ...
-
Different types of diagrams in UML : UseCase diagram Class diagram Object diagram State diagram Sequence diagram Collaboration diagram...
-
Virtual-Override and New Class Child inherits from Class Parent and has mehtod ShowVirtualOverride() and ShowNew() methods. Please see th...
-
Question : Name few C# 3.0 enhancements ? Answer : The C# 3.0 language enhancements are as follows: Implicitly typed local variables I...
-
If locaction attribute is specified, must be one of: Any, Client, Downstream, None, Server or ServerAndClient.
No comments:
Post a Comment