Kdb - string for double or floating

I'm trying to convert a string to double or float to KDB - the string contains a number with an "accounting" format of type 2,228,25 (quantity) - I use something like "j"$amount , which I get 50 44 50 50 56 46 50 53 as the return value. How to convert this string to the correct number? thanks

+5
source share
2 answers

When casting strings to other types of atoms in kdb +, you must use capital letters for the cast. Casting a string to a number with commas will return zero values, so try deleting them with either except or ssr.

 "J"$"2,228,25" except "," 

or

 "J"$ssr["2,228,25";",";""] 
+8
source

As indicated in another example, you can use except to exclude "," before converting. However, if you have many characters in the line that you want to delete, and they may vary, you can use inter and a list of accepted characters, and not have an exception:

 q)amt:"2/228,25.0" q)"F"$amt inter "0123456789." 222825f 
0
source

Source: https://habr.com/ru/post/1261217/


All Articles