jeudi 5 mars 2015

How to force decimal addition (#10) when adding numbers with a carry (octal issue)


How can I get 10#1$result to work correctly?


When creating a calculator for adding two numbers I am adding together by transversing the digits from small to large. e.g. for adding 51 plus 51 I am adding 1+1, storing the "2", then adding 5+5, storing the "0" and then adding the 1 at the beginning.


To do this I am using result=1$result


However I run into problems with numbers that have 8 and 9 in them. I discovered this recently and was able to solve it then by preceding it with 10#, e.g.



result=10#$((result))


However with the need for the "1" at the start for when I have a "10" as the result (record 0, then add the "1" at the start) I can't get the base 10 syntax to work right. I've tried:



result=10#1$((result))
result=10#(1$((result)))
result="10#1$((result))"


Aucun commentaire:

Enregistrer un commentaire