Search code examples
formattingkdb

Convert number to string and add comma to numbers every three digits kdb/q


I am converting integer in kdb/q to string and want comma every three digit in the string. How can I format numbers using a comma separator every three digits using kdb/q?

For example: Input 298 output: "298" input 2987 output: "2,987" input 234523565 output: "234,523,565"


Solution

  • One idea

    q){reverse","sv 0N 3#reverse string x}234523565
    "234,523,565"
    q){reverse","sv 0N 3#reverse string x}1000000000001
    "1,000,000,000,001"