The
Value
property returns an
object
, which doesn't have the standard formatting options.
The quick-and-dirty fix is to use
string.Format
:
lbl_RatePerDay.Text = string.Format("{0:F2}", dataGridView2.SelectedRows[0].Cells["Rate_Per_Day"].Value);
A more complete fix would be to create your own extension method:
public static class FormattingExtensions
{
public static string ToString(this object obj, string format, IFormatProvider formatProvider = null)
{
if (obj == null) throw new NullReferenceException();
var formattable = obj as IFormattable;
if (formattable == null) return obj.ToString();
return formattable.ToString(format, formatProvider);
}
}
Use:
lbl_RatePerDay.Text = dataGridView2.SelectedRows[0].Cells["Rate_Per_Day"].Value.ToString("F2");