Join us in Chat. Click link in menu bar to join. Unofficial chat day is every Friday night (US time).
0 Members and 1 Guest are viewing this topic.
float answer;answer = 2.5;
int base = 1, decimal = 25;int result;result = 4 * (base+pow(10,strlen(decimal)*(-1))*decimal); //result = 5
I don't think you can do float if you're using an 8-bit avr, but maybe you could store the base number and the decimal separately, and somehow come up with an algorithm that combines them when its time to do the math?
Just because the AVRs are 8 bit doesn't mean that it can only deal with 8 bit integers. It just means that its data bus is 8 bit wide. So accessing a 16-bit integer will require 2 read cycles and will require 2 registers to hold the value. A float or double needs more space, more cpu cycles, but it CAN be handled.
float test;test = 2.5;rprintfInit(uart2SendByte);rprintfFloat(3,test);
rprintfFloat(4,5.667); // displays the 4 digits of the number 5.667
Can't you also write 5/3 as 5/3.0 to receive a decimal number? I'm nearly positive I've done this with AVR's. You just have to declare a float or double right?