Share via


How can I assign a value to a Decimal or Integer Column

Question

Tuesday, May 14, 2013 7:55 PM

I have a "Benefit Amount" and a "Benefit Percentage" storage location on my Form. In some cases I store an Amount and in other cases a Percentage. How can I value my Global Variable for Amount to <NULL> if the Percentage is valid and vice versa?

I have this now...

            if (GlobalVariableClass.GlobalStrCSTypeCodeValue == "A  ")
            {
                string StrSTCDetailBenefitPct = NumericUpDownSTCMainSTCDetailBenefitPct.Value.ToString();
                GlobalVariableClass.GlobalStringSTCMainSTCDetailAddBenefitPct = StrSTCDetailBenefitPct;
                GlobalVariableClass.GlobalIntegerSTCMainSTCDetailAddBenefitPct = Convert.ToInt32(StrSTCDetailBenefitPct.ToString());
                GlobalVariableClass.GlobalStringSTCMainSTCDetailAddBenefitAmt = null;
                GlobalVariableClass.GlobalDecimalSTCMainSTCDetailAddBenefitAmt = Convert.ToDecimal(GlobalVariableClass.GlobalStringSTCMainSTCDetailAddBenefitAmt.ToString());
            }
            else
            {
                GlobalVariableClass.GlobalStringSTCMainSTCDetailAddBenefitPct = null;
                GlobalVariableClass.GlobalIntegerSTCMainSTCDetailAddBenefitPct = Convert.ToInt32(GlobalVariableClass.GlobalStringSTCMainSTCDetailAddBenefitPct.ToString());
            }

Any help is greatly appreciated.

And Thanks in  advance.

PSULionRP

All replies (2)

Tuesday, May 14, 2013 9:03 PM ✅Answered | 1 vote

You can use Nullable<Int32> or Nullable<Decimal> datatypes instead of Int32 or Decimal.

Muthukrishnan Ramasamy
net4.rmkrishnan.net
Use only what you need, Reduce global warming


Wednesday, May 15, 2013 5:41 AM ✅Answered | 1 vote

Sometimes, instead of nullable variables like ‘int ? Amount’, that accept null, you can use some reserved values that are not used in other cases, like ‘-1’. For example: ‘GlobalVariables.Amount = -1’.