AI Zone Admin Forum Add your forum

NEWS: survey on 3000 US and UK consumers shows it is time for chatbot integration in customer service!read more..

Treating numbers as strings

What I want is to be able to put 33.4359416 into a variable and use it as output or in a ^join() I want to treat it as a string. I do not want to do any math operations.

# All get rounded to 33.44
$$_lattitude = 33.4359416
$$_lattitude = ^‘33.4359416’
$$_lattitude = ^“33.4359416”

# single quotes stay, cannot get just the digits and period
$$_lattitude = ‘33.4359416’



  [ # 1 ]

$_lat = ^join(\” $_num \”)


  [ # 2 ]

Not sure how that works.

If I have json like

$_myloc = ^jsoncreate( ^'location : {
   lat : "33.4359416", 
   long : "-86.44345",
   address : "Hoover Alabma"

and then try to use it in a join like this:

$_myquery = ^join( ^$ $_myloc.location.long

the value of $_myquery is 33.44,-86.44

Is there anyway to not have the numbers treated as a string and not trucated?

the only way I have found is to put some type of non-numeric item in the string like:

$$_location = ^"33.4359416,-86.10580479999998" 

the comma prevents the truncation.


  [ # 3 ]

To prevent rounding to two decimal places then check out $cs_fullfloat.
You can also use the ^format() function to format a number to, say, 6 decimal places.


  [ # 4 ]

no joy :-(

$_myloc = ^jsoncreate( ^'location : {
   lat : "33.4359416", 
   long : "-86.44345",
   address : "Hoover Alabma"

joinlocation= ^formatFLOAT "%f" 33.4567885) , ^formatFLOAT "%f" $userpfData.location.long) & 

with :trace ^format turned on

you see
....,....System call ^format(`FLOAT`,`”%f”`,`33.46`)
....,....,NOPROBLEM ^format(FLOAT) => `33.460000`
....,....System call ^format(`FLOAT`,`”%f”`,`-86.44`)
....,....,NOPROBLEM ^format(FLOAT) => `-86.440000`

The first call to ^format with the literal makes me think that cs truncates to 2 decimal places before it does anything else.

BTW: I am running on Windows. I mention this because the manual for ^format says:

For integer, if you use a %d format, you will be using a 32-bit value. For ll formats you will be using 64-bit but it won’t work well on Windows output because Windows uses their own sprintf notation

A few other notes:
1) You have to have the format string in double quotes or else you get an empty result
2) putting the number literal in single or double quotes only results in ^format returning 0.000000
3) you can put the format string into a variable like $$_formatString = “%f” and it does not alter the bhavior.



  [ # 5 ]

So this works for me:

$_myloc = ^jsoncreatetransient object )
$ = ^join(\" 33.4359416 \"
$_myloc.long = ^join(\" -86.44345 \")
$_myloc.address "Hoover Alabama" 

Also with using variables or ^format() instead of hard-coded numbers.



  login or register to react