Force two decimal places in C#

c#

Solution

string output = value_f_d.ToString("#.00", CultureInfo.InvariantCulture);

(`using System.Globalization` in your using declarations at the top)

Problem

I've this problem and can't find a solution. This is super easy and i don't know why can't i find a solution. Problem: - if a value returns for example "16.60", in c# i'll read "16.6", but i need 0 as well, because of paypal API, wich only accepts a value with no decimal numbers, or if it has to have decimal numbers the minimum and maximum must be 2. So how can i make this? i've tried this: ``` string value_f = "16,6"; decimal value_f_d = decimal.Parse(value_f); value_f_d = (decimal)Math.Round(value_f_d, 2); value_f = value_f_d.ToString("#.##"); value_f = value_f.Replace(',', '.'); ``` i want this output: 16.60, but gives this: 16.6

Original source

Related problems