How to display decimal with 3 zeros after comma, without trailing? My code is
<td>@decimal.Parse(item.QuantityKg.ToString()).ToString("G29")</td>
Since your QuantityKg is decimal? instead of decimal, you can use it's Value property and use "N" format specifier with 3 precision.
If everything is okey other than this, this should work in your case;
<td>@item.QuantityKg.Value.ToString("N3")</td>
But this throws InvalidOperationException if QuantityKg is null, so using string.Format would be better to catch this situation which generates empty string if it is null as Panagiotis mentioned.
<td>@string.Format("{0:N3}", item.QuantityKg)</td>
decimal or decimal?
ToString("N3")instead?QuantityKg?decimalif it is alreadydecimal? Why not just<td>@item.QuantityKg.ToString("N3")</td>instead?String.Format("{0:N3}",item.QuantityKg)will work with bothdecimalanddecimal?. As a rule,String.Formatworks even if a type's specificToString()doesn't allow a formatting string