I need to convert a value from an int16 to a float - how can I do this? Are there any rounding options in CCS? i.e. if int16 valA = 4 and i divide it by 3 to get a float value how can i round the float value up or down?
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
Posted: Thu Jun 21, 2007 9:53 am
This is standard C. Get yourself a copy of any good C book, especially K&R (The C Programming Language" by Kernighan and Ritchie, ISBN 0-13-110362-8).
For your question:
int16 valA = 4;
float valB;
valB = valA/3 returns 1.0 because 4/3 => 1 using integer math
valB = valA/3.0 returns 1.333... because 4/3.0 uses float math
valB = (float)valA/3 returns 1.333... because 4.0/3 uses float math
You will have to do rounding yourself. _________________ The search for better is endless. Instead simply find very good and get the job done.
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum