-3

I have a class with json properties and I would like it to receive an integer which is the number of zeros that should be multiplied only for the decimal properties.

2 = multiply by 100 3 = multiply by 1000 etc

...

[JsonProperty("max_total_txn_value")]
        public decimal MaxTotalTxnValue
        {
            //example: multiplying to 2 (2 zeros)
            get { return maxTotalTxnValue / 100; }
            set { maxTotalTxnValue = value * 100; }
        }

...

...

[JsonConstructor]
{
//some code mabe here
}

...

Example:

if I pass 3 (int)

12.00 (value decimal)

12.00 x 1000(3 zeros)

Result: 12000

1 Answers1

-1

To use in your class, just use it as you would any other property.

public int PowerOfTenFromJsonDeserialization { get; set; }

public decimal MaxTotalTxnValue => initialValue * Math.Pow(10, int.Parse(PowerOfTenFromJsonDeserialization));

I can't really expand much since I don't know what your class looks like, or your end goal, but I do know the above would work for your general approach. Just need to adapt it to your needs.

Ingenioushax
  • 718
  • 5
  • 20