format double to 2 decimal places in csharp

Code Example - format double to 2 decimal places in csharp

                
                        priceLbl.Text = price.ToString("0.##");
                    
                
 

csharp double value with 2 decimal places

                        
                                inputValue = Math.Round(inputValue, 2);
                            
                        
 

csharp display float with 2 decimal places

                        
                                myFloatVariable.ToString("0.00"); //2dp Number

myFloatVariable.ToString("n2"); // 2dp Number

myFloatVariable.ToString("c2"); // 2dp currency
                            
                        
 

csharp decimal vs double

                        
                                Use decimal for manmade concepts like currency
Use double/float for naturally-occuring values like temperature