<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>Question Re: JSON string to integer in groovy script removing lead... in Technology Q&amp;A</title>
    <link>https://community.sap.com/t5/technology-q-a/json-string-to-integer-in-groovy-script-removing-leading-zero-s/qaa-p/13613773#M4819207</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;what&amp;nbsp;&lt;SPAN class=""&gt;&lt;A class="" href="https://community.sap.com/t5/user/viewprofilepage/user-id/219722" target="_self"&gt;&lt;SPAN class=""&gt;sachin_yadav3&lt;/SPAN&gt;&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;proposed will not work. I think he is mixing it up. It's not about to remove leading zeros because that would then work already right now. It's about how to maintain the leading zeros. The answer is actually: it's impossible.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;Mathematical, there are no leading zeros. The first integer number 1 is "1" it's not "01" because then it would mathematical not clear actually how many "leading zeros" you have. Is 1 maybe "00001" or is it "00000000000001" or .... etc. So integer numbers by definition do not have any leading zeros, ever.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;If you want to keep using the leading zeros, you have to get rid of your code line where you convert it to double and parse it to integer:&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="java"&gt;object.issuer.branchCode.toDouble().intValue();&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;this line of coding will always remove the leading zeros. Get rid of the "toDouble().intValue()". And check if you make use of toString() or if leaving it just like it is isn't already fine enough for you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best,&lt;/P&gt;&lt;P class=""&gt;Edrilan Berisha&lt;/P&gt;&lt;P class=""&gt;SAP S/4HANA Cloud Financials Development&lt;/P&gt;</description>
    <pubDate>Thu, 29 Feb 2024 13:57:54 GMT</pubDate>
    <dc:creator>Edrilan_Berisha</dc:creator>
    <dc:date>2024-02-29T13:57:54Z</dc:date>
    <item>
      <title>JSON string to integer in groovy script removing leading zero's</title>
      <link>https://community.sap.com/t5/technology-q-a/json-string-to-integer-in-groovy-script-removing-leading-zero-s/qaq-p/13612023</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a requirement where in JSON value need to be send as integer instead of string.&lt;/P&gt;&lt;P&gt;Method in groovy script is:&amp;nbsp;&lt;/P&gt;&lt;P&gt;def json = message.getBody(java.lang.String)&lt;BR /&gt;def jsonSlurper = new JsonSlurper()&lt;BR /&gt;def object = jsonSlurper.parseText(json)object.issuer.branchCode = object.issuer.branchCode.toDouble().intValue();&lt;/P&gt;&lt;P&gt;Value is&amp;nbsp;branchCode: "0732340"&lt;/P&gt;&lt;P&gt;Output of above groovy is&amp;nbsp;branchCode: 732340&lt;/P&gt;&lt;P&gt;Expected output is :&amp;nbsp;branchCode: 0732340&lt;/P&gt;&lt;P&gt;Please help with changes that can be done in the code or any alternate code which can be used.&lt;/P&gt;&lt;P&gt;Thanks &amp;amp; Regards,&lt;/P&gt;&lt;P&gt;Mayank&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 20 Feb 2024 12:09:54 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/json-string-to-integer-in-groovy-script-removing-leading-zero-s/qaq-p/13612023</guid>
      <dc:creator>mayank_g</dc:creator>
      <dc:date>2024-02-20T12:09:54Z</dc:date>
    </item>
    <item>
      <title>Re: JSON string to integer in groovy script removing lead...</title>
      <link>https://community.sap.com/t5/technology-q-a/json-string-to-integer-in-groovy-script-removing-leading-zero-s/qaa-p/13612855#M4819107</link>
      <description>&lt;P&gt;Hi ,&amp;nbsp;&lt;/P&gt;&lt;P&gt;Try by defining&amp;nbsp;&lt;SPAN&gt;object as integer i.e.&amp;nbsp;&lt;/SPAN&gt;&amp;nbsp;int&amp;nbsp;&lt;SPAN&gt;object =&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Thanks&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 20 Feb 2024 14:33:54 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/json-string-to-integer-in-groovy-script-removing-leading-zero-s/qaa-p/13612855#M4819107</guid>
      <dc:creator>sachin_yadav3</dc:creator>
      <dc:date>2024-02-20T14:33:54Z</dc:date>
    </item>
    <item>
      <title>Re: JSON string to integer in groovy script removing lead...</title>
      <link>https://community.sap.com/t5/technology-q-a/json-string-to-integer-in-groovy-script-removing-leading-zero-s/qaa-p/13613773#M4819207</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;what&amp;nbsp;&lt;SPAN class=""&gt;&lt;A class="" href="https://community.sap.com/t5/user/viewprofilepage/user-id/219722" target="_self"&gt;&lt;SPAN class=""&gt;sachin_yadav3&lt;/SPAN&gt;&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;proposed will not work. I think he is mixing it up. It's not about to remove leading zeros because that would then work already right now. It's about how to maintain the leading zeros. The answer is actually: it's impossible.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;Mathematical, there are no leading zeros. The first integer number 1 is "1" it's not "01" because then it would mathematical not clear actually how many "leading zeros" you have. Is 1 maybe "00001" or is it "00000000000001" or .... etc. So integer numbers by definition do not have any leading zeros, ever.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;If you want to keep using the leading zeros, you have to get rid of your code line where you convert it to double and parse it to integer:&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="java"&gt;object.issuer.branchCode.toDouble().intValue();&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;this line of coding will always remove the leading zeros. Get rid of the "toDouble().intValue()". And check if you make use of toString() or if leaving it just like it is isn't already fine enough for you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best,&lt;/P&gt;&lt;P class=""&gt;Edrilan Berisha&lt;/P&gt;&lt;P class=""&gt;SAP S/4HANA Cloud Financials Development&lt;/P&gt;</description>
      <pubDate>Thu, 29 Feb 2024 13:57:54 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/json-string-to-integer-in-groovy-script-removing-leading-zero-s/qaa-p/13613773#M4819207</guid>
      <dc:creator>Edrilan_Berisha</dc:creator>
      <dc:date>2024-02-29T13:57:54Z</dc:date>
    </item>
  </channel>
</rss>

