printf formatting date time floats - Kdb+ / qStudio

Home Forums Kdb+ / qStudio printf formatting date time floats

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
  • #141


    What support does kdb have for handling and formatting numbers? dates?

    Often I find myself asked by the users to provide “nicely” formatted numbers and have to suggest they handle that on their end in excel or C#.

    Am I missing something? What is available?


    For formatting numbers especially floats with decimal places there are two useful functions .Q.fmt and .Q.f

    .Q.fmt [x;y] – takes two arguments, x the total number of characters, y the number of decimal places.

    q).Q.fmt[6;2]each 1 2.1 3.45678 200 2000
    " 1.00"
    " 2.10"
    " 3.46"

    .Q.f – takes one argument, the number of decimal places to show.

    q)\P 0
    q).Q.f[2;]each 9.996 34.3445 7817047037.90 781704703567.90 -.02 9.996 -0.0001

    Notice \P is used here to control the precision of floating point numbers, it affects many areas throughout kdb (saving as csv, web browser…). Also notice that I needed to use each with both these functions as they operate on atoms.



    That is useful but is there no printf?



    You could import printf like functionality using a C shared library (windows DLL, Linuz .so)

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.