Format String for Decimal {0:D2}
-
Hi, I've been trying to format some fields as Decimal numbers but not as currency. The other numeric formats work great (currency, scientific notation, etc.) and the "D" works fine with Dates. The "D" will not work for me on a numeric field though. I've tried both embedding in the DataBinder statement:
<%# DataBinder.Eval(Container, "DataItem.AmountPaid", "{0:D2}") %>
and as a DataFormatString:DataFormatString="{0:D2}"
I've also tried the ItemDataBound event. No luck. Any suggestions? Will -
Hi, I've been trying to format some fields as Decimal numbers but not as currency. The other numeric formats work great (currency, scientific notation, etc.) and the "D" works fine with Dates. The "D" will not work for me on a numeric field though. I've tried both embedding in the DataBinder statement:
<%# DataBinder.Eval(Container, "DataItem.AmountPaid", "{0:D2}") %>
and as a DataFormatString:DataFormatString="{0:D2}"
I've also tried the ItemDataBound event. No luck. Any suggestions? WillAre you just trying to display two decimal places? If so, use the F format specifier:
Decimal pi = new Decimal (Math.PI); Console.WriteLine ("{0:F2}", pi);
Jon Sagara When I grow up, I'm changing my name to Joe Kickass! My Site | My Blog | My Articles
-
Hi, I've been trying to format some fields as Decimal numbers but not as currency. The other numeric formats work great (currency, scientific notation, etc.) and the "D" works fine with Dates. The "D" will not work for me on a numeric field though. I've tried both embedding in the DataBinder statement:
<%# DataBinder.Eval(Container, "DataItem.AmountPaid", "{0:D2}") %>
and as a DataFormatString:DataFormatString="{0:D2}"
I've also tried the ItemDataBound event. No luck. Any suggestions? Will -
Are you just trying to display two decimal places? If so, use the F format specifier:
Decimal pi = new Decimal (Math.PI); Console.WriteLine ("{0:F2}", pi);
Jon Sagara When I grow up, I'm changing my name to Joe Kickass! My Site | My Blog | My Articles
Thanks! That's doing it for me. I ignored the "F" because description in the MSDN doc is pretty vague (fixed) . . . until you follow the chain to the "Standard Numeric Format Strings". I just didn't go far enough the first time. I also see there that the "D" only works with integral types as the other poster suggested. I'm not sure what type results from the DataBinder statement? Evidently it's not a String or Decimal. Thanks again.
-
What is the data type of the field? The "D" specifier will only work with integral types.
--- b { font-weight: normal; }
I'm not sure what type results from the DataBinder statement? Evidently it's not a String or Decimal. But, I see what you mean now that I found "Standard Numeric Format Strings" item in the MSDN doc. I circumvented the issue by using the Fixed format instead. Some time when I'm not under the gun I'll have to follow up and figure this one out. Thanks.
-
I'm not sure what type results from the DataBinder statement? Evidently it's not a String or Decimal. But, I see what you mean now that I found "Standard Numeric Format Strings" item in the MSDN doc. I circumvented the issue by using the Fixed format instead. Some time when I'm not under the gun I'll have to follow up and figure this one out. Thanks.