AI Zone Admin Forum Add your forum

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

Value changes to exponential value
 
 

{
"message": "Request Completed Successfully",
"code": 200,
"data": [{

"Year": {
"originalValue": "2017",
"displayValue": "2017",
"label": "Year"
},
  “Transaction”: {
"originalValue": 7049542752.056771,
"displayValue": "704.95 Crores",
"label": "Total Value"
}
}]
}
The above is json response obtained after i make an external call to a service, when i parse the json to get the value originalValue, the value 7049542752.056771 changes to exponential value 7.049542752056771E9 , i want to do value comparison, but i am not able to do comparison correctly as the values are in exponential format.

How can I get the actual value same as the json values?

Following is the code i used for json parsing:

          $$user_agent = ^“[email protected] User-Agent: Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0)”
          $$header = ^” ~Accept: application/json “
          $$tmp = ^jsonopen(transient POST $dataAPI $_json $$header $$user_agent)
          $_cnt = ^length($$tmp.data)
          $_index = 0
          $originalValue = 0
          ^loop($_cnt) {
$salesValue = jsonpath(.data.$_index.Transaction.displayValue ^jsonparse($$tmp))
$originalValue = jsonpath(.data.$_index.Transaction.originalValue ^jsonparse($$tmp))
$_index += 1
}

Please review the code.

 

 
  [ # 1 ]

You already posted this basic question in a different thread. The code above doesnt even TRY to compare the values.

 

 
  [ # 2 ]

Those two numbers are the same and so they will be equal. What you are seeing with the “exponential” version is the default presentation of C’s “g” format.
Even though everything in CS is basically text, if a word contains only number characters then it will be treated as such in any comparison and in any arithmetic operation.

If you are concerned about the presentation of the number then check out the ^format() function.

On another point, your code could be improved.

$_cnt = ^length($$tmp.data)
     
$_index 0
     $originalValue 
0
     
^loop($_cnt{
          $salesValue 
= $$tmp.data[$_index].Transaction.displayValue
          $originalValue 
= $$tmp.data[$_index].Transaction.originalValue
          $_index 
+= 1
     } 

 

 

 
  [ # 3 ]

Thanks. The thing is i wanted to compare the 7049542752.056771 with other value in CS code, but CS coverts the number to exponential form and due to which i am not able to compare the two numbers. For example, the code snippet:


$originalValue = $$tmp.data[$_index].Transaction.originalValue
$a = $originalValue
$b = 4.763363383874744E9
if($a > $b){
$a is greater than $b
}
else{
$b is greater than $a
}

CS fails to compare this two values. Is there a way to implement the same ?

 

 
  [ # 4 ]

OK. please follow up ONLY in the other thread you spawned first. No need to be in two threads here.

 

 
  login or register to react