To avoid the error when an invalid string is passed in, use
the decimal.TryParse
method[
^].
As to why you're getting an error when you pass in
".15"
, check your regional settings. It's possible that the decimal separator is not the
"."
character.
Also, since your parameters are already strings, there's no need to call
.ToString()
on them.
public void TAPFPMcal(string FPR, string RPM)
{
if (!decimal.TryParse(RPM, out DRPM))
{
DRPM = 0;
}
if (!decimal.TryParse(FPR, out DFPM))
{
DFPM = 0;
}
if (DFPM != 0)
{
decimal FEED = DRPM * DFPM;
FPM = Math.Round(FEED, 2).ToString();
}
else
{
FPM = "0.0000";
}
}