DaveGuest
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"
"200.00"
"******"
.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
"10.00"
"34.34"
"7817047037.90"
"781704703567.90"
"-0.02"
"10.00"
"-0.00"
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.
DaveGuest
That is useful but is there no printf?
You could import printf like functionality using a C shared library (windows DLL, Linuz .so)