Arturo Martinez Arturo Martinez - 1 month ago 9
C# Question

Remove Decimal form String if equals to ".00"

Im having alot of problems trying to take out the decimal part of my string,
the string comes from a var type in my view like this:

var temp = dashList[index];
@PrintSection(actualDate, Model, String.Format("{0:0.000}", temp.Rubro))**


temp.Rubro is my String part that can be ".00" or ".XX"

however i need to take the decimal part of the string only when its value is ".00"
since i have some values of the dashlist have important decimal parts.

Is there a way to take the decimal part of a string only if it equals to ".00"???

The output im trying to get is:

From XX.00 -> XX
From XX.12 -> XX.12


both kinds are on my list

Answer

Try this:

var temp = dashList[index];
@PrintSection(actualDate, Model, String.Format("{0:0.000}", temp.Rubro).Replace(".00", ""))