precision with c++ interfaces

When I download data to c++ code, I see that floating point data is rounded to only 2 decimal places.
I have tried declaring other doubles with more decimal digits and they can be printed fine.

Is there a way to change this in the interface?

Regards,

On further checking it seems that c++ can only download 7 digits(including the decimal) from kdb server.
So it can download 45.1799 or 5432.15.

Any way I can fix this?

On Wednesday, December 4, 2013 2:08:41 PM UTC+5:30, naveen sharma wrote:

When I download data to c++ code, I see that floating point data is rounded to only 2 decimal places.
I have tried declaring other doubles with more decimal digits and they can be printed fine.

Is there a way to change this in the interface?

Regards,

If you are retrieving the binary representation of these floats, the only restriction is that of IEEE754, which is the same for c/c++. If you are retrieving the stringified representation from the server, this is controlled by \P.

e.g.

q)22%7

3.142857

q)\P 0

q)22%7

3.1428571428571428

see http://code.kx.com/wiki/Reference/DisplayPrecision

maybe you can post some c code to show what you are doing?

K getTwoDat(servParams& spar, corrParams& cpar, string& dt)

{

        string query = “corrTwoDat[” + cpar.symIn + “;” + to_string(cpar.interval) + “;” + dt + “]”;

        K flip, result, columnNames, data, dtlist, procDict;

        int row, col, nCols, nRows, handle=khp((S)(spar.host).c_str(), spar.port);

        if(handle<0)printf(“Cannot connect\n”),exit(1);

        else if(!handle)printf(“Wrong credentials\n”),exit(1);

        result=k(handle,(S)query.c_str(),(K)0);

        if(!result)

                printf(“Network Error\n”),perror(“Network”),exit(1);

        if(result->t==-128)

                printf(“Server Error %s\n”,result->s),kclose(handle),exit(1);

        kclose(handle);

        if(result->t!=99&&result->t!=98) // accept table or dict

                printf(“type %d\n”,result->t),r0(result),exit(1);

        flip = kK(result->k)[1];

        //flip = (result->k)[1];

        //procDict = kK(

        cout << kE(kK(flip)[35])[0] << “ss \n”;

        return(flip);

}

This gets me the data. And as you can see the last line of the function prints just the two digits after decimal.

Another weird thing, Running \P 0 doesn’t change the display of 22%7. I still get only 7 digits after decimal.

does this help?

http://www.cplusplus.com/reference/iomanip/setprecision/

yes, type real will stringify to max[8;system"P"].
But I believe your issue here is with stringify of a single precision float in c++, not kdb+.

Thanks Charles!
It was just a display issue