SparkFun Forums 

Where electronics enthusiasts find answers.

Discussions on how to get your MSP JTAG programmer up and running.
By SSK
#62466
Hello forum members,

Does anyone having a code for converting float value to integer for MSP430 controller?? Even assembly routine will also be helpful.

Thanks in advance.
User avatar
By leon_heller
#62467
If you aren't concerned about rounding you could just cast it to an int.

Leon
By inventore123
#62492
And if you want to keep some decimal digit you can use the "fixed point" trick:
This is an example to keep two decimal digits;

float f=1.2345678;
int i;
i=(int)(f*100);

i will be 123, with 1 being the integer part and 23 being the decimal part. All other digits are truncated.
If then you want to print i, use
printf("%d.%d\n",i/100,abs(i%100));
(assuming the MSP430 library has printf, and assuming it is redirected to something useful)