Re: ESQL/C float data
Posted in 1994
In article <2h5ba5$t7m@news.csie.nctu.edu.tw> ray@info.motctl.gov.tw (Cheng Kuang-Jui) writes: >I encounter a precision problem when I want to select a column with > >float data type. The value i inserted was "15.20", and when i use > >isql to check, it's fine. But if I used a double type host variable > >to get its value in my ESQL/C program, it got "15.199999". Could I > >get the correct data value, or should I change that column's data type > >if the correct value is very important? > >-- Thanks in Advance --- > >//ray Tried e-mail and was bounced back .. Why not just write a function that rounds it to 2 digits: void roundit(float *f) { int i,a; float x,nf,f_digits,bun1,num2; i=(int)*f; f_digits=*f-1; nf=*f-f_digits; num1=f_digits*100; a=num1; num2=num1-a; if(num2>.5) *f=(float) i + (float) (a+1)/100; else *f=(float) i + (float) (a)/100; } Compile this and link it to your program and call it before you use your float variable. Bob Beaulieu bobb@netcom.com