0

Have a variable containing a value like '000000017733'. - Need to convert it to '000000177,33' - Then make a sum with other variable. - Then convert it again to a string that will look like (for example) '000000008921'

XBASE

any one can help?

something like: **variables VGCA = 77,33 TOT = '000000017733'

** convert TOT to 177,33

** do the needed operation FINALV = TOT - VCGA

** reconvert FINALV from 100,00 to 000000010000

Rui Pires
  • 1
  • 3
  • what does the comma in the converted variable represent? The decimal point or is it some custom format? – stolen_leaves May 20 '20 at 11:57
  • Hello. the decimal point – Rui Pires May 20 '20 at 11:57
  • Just convert the '000000017733' to a float/double 17733.00 -> divide by 100 -> Perform necessay additions -> Multiply by 100 (to get rid of the decimal point) -> convert back to string with left padding. Personally I feel, you can skip the whole decimal point operations as for only additions, it won't really matter. All these are basic operations in all programming languages. – stolen_leaves May 20 '20 at 12:06
  • allready tryed with float but, probably I'm doing something wrong. I believe that its basic operations but I'm a basic developer :) can u give some help with the code. thanx – Rui Pires May 20 '20 at 13:57

1 Answers1

1

Don't know if you still need this or not, but in python 3 the code would look like this -

vgca = 77.33
tot = '000000017733'
tot_float = float(tot)/100
print(tot_float)
finalv = tot_float - vgca
finalv *= 100
finalv_string = format("%012d"%finalv)
print(finalv_string)

the output is -

177.33
000000010000
stolen_leaves
  • 1,441
  • 11
  • 19