Question

I need correct sample of using decimal format and decimal rounding to closest integer.

Sample1: I have number 123.345,51 result need to be 123.346,00

Sample2: I have number 123.345,49 result need to be 123.345,00

I found samples but they all use format with comma first 123,345.00 I need in first place point like 123.345,00

Tried with culture info but did not success ..

Sample code:

var amount = 123.345,77;
var cultureInfo = CultureInfo.GetCultureInfo("da-DK");
var formattedAmount = String.Format(cultureInfo, "{0:C}", amount);

When I need to convert formattedAmount to decimal its breaks... I am converting for Rounding values after ,

Was it helpful?

Solution

Solution is to enable users to input in format they want, like 123123,55 then use .Replace(",", ".") to replace , colon character with dot, after that made Decimal.Round and all problem are solved!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top