Using GCC on the Ubuntu Linux 10.04, I have unwanted rounding after a division.
I tried:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void FormatReading(int temp)
{
    double reading = temp / 100;
    printf("%f\n",reading);  /* displays 226.000000, was expecting 226.60 */
}
int main(void)
{
    FormatReading(22660);
    return 0;
}
It was suggested to me to try:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void FormatReading(int temp)
{
    long reading = temp ;
    reading = reading / 100;
    printf("%3.2ld\n",reading);  /* displays 226 */
}
int main(void)
{
    FormatReading(22660);
    return 0;
}
I also tried:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void FormatReading(int temp)
{
    long reading = temp ;
    double reading2 = reading / 100;
    printf("%3.2f\n",reading2);  /* displays 226.00 */
}
int main(void)
{
    FormatReading(22660);
    return 0;
}
I also tried the round function using include math.h with compiler tag -lm in various ways, but did not find what I was looking for.
Any help greatly appreciated.
Best regards, Bert
 
     
     
    