<?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>topic Re: dataframe - cast string to decimal when encountering zeros returns OE-16 in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/dataframe-cast-string-to-decimal-when-encountering-zeros-returns/m-p/26059#M18184</link>
    <description>&lt;P&gt;If the scale of decimal type is greater than 6, scientific notation kicks in hence seeing&amp;nbsp;0E-16.&lt;/P&gt;&lt;P&gt;This behavior is described in the existing OSS spark issue - &lt;A href="https://issues.apache.org/jira/browse/SPARK-25177" alt="https://issues.apache.org/jira/browse/SPARK-25177" target="_blank"&gt;https://issues.apache.org/jira/browse/SPARK-25177&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Kindly cast the column to a decimal type less than or equal to 6 to have zeros displayed as zeros. &lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;from pyspark.sql import functions as F
df = spark.sql("select cast('0' AS decimal(10,6)) as decimal_number union all select cast('1.0000123400000' AS decimal(4,2))")
df2 = df.withColumn("string_column", F.expr("format_number(decimal_number, '0.######################')"))
display(df2)  &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 09 Mar 2022 22:19:39 GMT</pubDate>
    <dc:creator>shan_chandra</dc:creator>
    <dc:date>2022-03-09T22:19:39Z</dc:date>
    <item>
      <title>dataframe - cast string to decimal when encountering zeros returns OE-16</title>
      <link>https://community.databricks.com/t5/data-engineering/dataframe-cast-string-to-decimal-when-encountering-zeros-returns/m-p/26058#M18183</link>
      <description>&lt;P&gt;The user is trying to cast&amp;nbsp;string to decimal when encountering&amp;nbsp;zeros. The cast function displays the&amp;nbsp;&amp;nbsp;'0'  as '0E-16'. could you please let us know your thoughts on whether 0s can be displayed as 0s?&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;from pyspark.sql import functions as F
df = spark.sql("select cast('0' AS decimal(38,16)) as decimal_number union all select cast('1.0000123400000' AS decimal(38,16))")
df2 = df.withColumn("string_column", F.expr("format_number(decimal_number, '0.######################')"))
display(df2)  &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="Screen Shot 2022-03-09 at 12.13.11 PM"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/2040i360C34D041CDEE90/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screen Shot 2022-03-09 at 12.13.11 PM" alt="Screen Shot 2022-03-09 at 12.13.11 PM" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 09 Mar 2022 22:12:04 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/dataframe-cast-string-to-decimal-when-encountering-zeros-returns/m-p/26058#M18183</guid>
      <dc:creator>shan_chandra</dc:creator>
      <dc:date>2022-03-09T22:12:04Z</dc:date>
    </item>
    <item>
      <title>Re: dataframe - cast string to decimal when encountering zeros returns OE-16</title>
      <link>https://community.databricks.com/t5/data-engineering/dataframe-cast-string-to-decimal-when-encountering-zeros-returns/m-p/26059#M18184</link>
      <description>&lt;P&gt;If the scale of decimal type is greater than 6, scientific notation kicks in hence seeing&amp;nbsp;0E-16.&lt;/P&gt;&lt;P&gt;This behavior is described in the existing OSS spark issue - &lt;A href="https://issues.apache.org/jira/browse/SPARK-25177" alt="https://issues.apache.org/jira/browse/SPARK-25177" target="_blank"&gt;https://issues.apache.org/jira/browse/SPARK-25177&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Kindly cast the column to a decimal type less than or equal to 6 to have zeros displayed as zeros. &lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;from pyspark.sql import functions as F
df = spark.sql("select cast('0' AS decimal(10,6)) as decimal_number union all select cast('1.0000123400000' AS decimal(4,2))")
df2 = df.withColumn("string_column", F.expr("format_number(decimal_number, '0.######################')"))
display(df2)  &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 09 Mar 2022 22:19:39 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/dataframe-cast-string-to-decimal-when-encountering-zeros-returns/m-p/26059#M18184</guid>
      <dc:creator>shan_chandra</dc:creator>
      <dc:date>2022-03-09T22:19:39Z</dc:date>
    </item>
  </channel>
</rss>

