decimalVar.ToString("#.##"); // returns ".5" when decimalVar == 0.5m
or
decimalVar.ToString("0.##"); // returns "0.5" when decimalVar == 0.5m
or
decimalVar.ToString("0.00"); // returns "0.50" when decimalVar == 0.5m
More Related Contents:
- .NET String.Format() to add commas in thousands place for a number
- Remove trailing zeros
- Decimal precision and scale in EF Code First
- Parse C# string to DateTime
- Generating a Random Decimal in C#
- Why c# decimals can’t be initialized without the M suffix?
- How to round decimal value up to nearest 0.05 value?
- How do I convert a decimal to an int in C#?
- How do I decompile a .NET EXE into readable C# source code?
- TAP global exception handler
- Reading a CSV file in .NET?
- .NET: Simplest way to send POST with data and read response
- Does .NET provide an easy way convert bytes to KB, MB, GB, etc.?
- C# dictionary – one key, many values
- Currency format for display
- What’s the best strategy for Equals and GetHashCode?
- C# – Fill a combo box with a DataTable
- Is there Windows system event on active window changed?
- Discovering derived types using reflection
- Show Transparent Loading Spinner above other Controls
- System.Net.WebClient unreasonably slow
- MemoryStream – Cannot access a closed Stream
- C#: Seeking PNG Compression algorithm/library [closed]
- What is causing NotSupportedException (“The given path’s format is not supported”) while using a valid path?
- Using GetProperties() with BindingFlags.DeclaredOnly in .NET Reflection
- How to capture mouse wheel on panel?
- C# System.RegEx matches LF when it should not
- click on a button in another application from my C# application?
- How to detect when laptop power cable has been disconnected?
- Custom Color Palette in Visual Studio Color Property Editor