2

I am looking for a way to convert strings to a float for a division and then convert back to strings afterwards.

Strings;

scalavars.ExchangeValue
scalavars.Rate

int:

scalavars.CurrencyAmount

All contain values and I am trying to complete this equation;

scalavars.ExchangeValue = scalavars.CurrencyAmount / scalavars.Rate

How can I convert all three to floats for the division and then convert back to their orignal types and store the result in scalavars.ExchangeValue as a string again?

Jeksk
  • 21
  • 1

1 Answers1

0

Try this:

scalavars.ExchangeValue = str(float(scalavars.CurrencyAmount) / float(scalavars.Rate))
Lynn
  • 10,425
  • 43
  • 75
  • Thanks, this works great. Any way to round it to 2 decimal places in the same line? – Jeksk Jul 16 '15 at 15:06
  • 1
    Got it, never mind - `scalavars.ExchangeValue = str(round(float(scalavars.CurrencyAmount) / float(scalavars.Rate), 2))` – Jeksk Jul 16 '15 at 15:22