Search code examples
printingkdb

How to format doubles in kdb+


Is there a printf-like function in kdb q? I'm trying to format double fields to 4 digit precision. The equivalent printf formatting would be "%.04f".


Solution

  • .Q.f is probably what you're looking for:

    http://code.kx.com/q/ref/dotq/#qf-format

    q).Q.f[2;100]
    "100.00"
    q).Q.f[2;100.8888]
    "100.89"