Hallo, Is it possible, that I can add the strings '1' '.' and '2'. I want to add this 3 strings: 1.2 and convert it into a float value and than I want add a float value.
"Simple it is. But also, unfortunately, wrong. One would have to divide by 10.0 instead of 10"
Oops - so one would!
"floating-point arithmetic on an embedded CPU like the 251 is generally a dubious choice"
That's my excuse - I never touch the stuff, so missed the obvious detail... ;-)
Adds another side the "Sledgehammer to crack nut" title, though!
One way to avoid floating-point is to choose one's units appropriately; eg, instead of using "5.2 whatsits", use "52 centi-whatsits" or 520 milli-whatsits" - and then use integer arithmetic.
eg, in this case:
int num_val; num_val = (MDU[0]-'0')*10; // Numerical value of the 1st character; // ie, the tens digit in centi-whatsits num_val += (MDU[2]-'0'); ; // Numerical value of the 3rd character; // ie, the units digit in centi-whatsits
or
int num_val; num_val = (MDU[0]-'0')*100; // Numerical value of the 1st character; // ie, the hundreds digit in milli-whatsits num_val += (MDU[2]-'0')*10; // Numerical value of the 3rd character; // ie, the tens digit in milli-whatsits
Erm, at the risk of being a pest, I'm afraid your blow missed the nut by an order of magnitude, which is bad even for a sledgehammer: 5.2 whatsits is 520 centi-whatsits.
But I'm willing to forgive people educated on "imperial" units for mixing up their SI prefixes --- as long as they extend similar courtesy to people baffled by the relation between inches and pints. ;-)
What can I say? Guitly as charged, m'lud.
"as long as they extend similar courtesy to people baffled by the relation between inches and pints"
Imperial pints not to be confused with US pints, of course...
Of course, my milli-whatsits were out by the same order of magnitude.