- I was working with integration, where i need to send my internal data to Core system. I have came across a strange issue while converting large number(Double) into JSON.
- Sales-force automatically converting number into exponent. Below is sample json i have to trying to resolve,In real scenario my JSON is holding very large content. Does any know how to resolve this issue?
Sample Json format trying to generate:
{ "Amount":45454544.00 }
Example 1:
Double num1=45454544.00;
String str= '{"Amount":' + num1 + '}';
system.debug(str);
Example 2:
Map<String,Double> num2=new Map<String,Double>{'Amount'=>45454544.00};
system.debug(JSON.Serialize(num2));
Output for the above code:
{"Amount":4.5454544E7}
Core system is throwing an error, because it unable to resolve exponent form.
Question Updated:
Using decimal will still has an issue while converting larger number.
Double num1=45454544545546556.23;
Decimal num3= (Decimal)num1;
String str= '{"Amount":' + String.valueOf(num3) + '}';
system.debug(str);
output: {"Amount":4.545454454554656E+16}