Using custom number format C# with Example



Using custom number format C# with Example

NumberFormatInfo can be used for formatting both integer and float numbers. 
// invariantResult is "1,234,567.89" 
var invarianResult = string.Format(CultureInfo.InvariantCulture, "{0:#,###,##}", 1234567.89); 
// NumberFormatInfo is one of classes that implement IFormatProvider 
var customProvider = new NumberFormatInfo 
{ 
NumberDecimalSeparator = "_NS_", // will be used instead of ',' 
NumberGroupSeparator = "_GS_", // will be used instead of '.' 
}; 
// customResult is "1_GS_234_GS_567_NS_89" 
var customResult = string.Format(customProvider, "{0:#,###.##}", 1234567.89); 

0 Comment's

Comment Form

Submit Comment