<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: AVG Decimal simplejson (Decimal is not JSON serializable)</title>
	<atom:link href="http://www.djangofoo.com/228/avg-decimal-simplejson-decimal-is-not-json-serializable/feed" rel="self" type="application/rss+xml" />
	<link>http://www.djangofoo.com/228/avg-decimal-simplejson-decimal-is-not-json-serializable</link>
	<description>Django Tips and Tweaks</description>
	<lastBuildDate>Fri, 25 Mar 2011 12:22:36 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
	<item>
		<title>By: Panos Laganakos</title>
		<link>http://www.djangofoo.com/228/avg-decimal-simplejson-decimal-is-not-json-serializable/comment-page-1#comment-535</link>
		<dc:creator>Panos Laganakos</dc:creator>
		<pubDate>Mon, 25 Oct 2010 13:25:30 +0000</pubDate>
		<guid isPermaLink="false">http://www.djangofoo.com/?p=228#comment-535</guid>
		<description>Thanks mate!</description>
		<content:encoded><![CDATA[<p>Thanks mate!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ryan</title>
		<link>http://www.djangofoo.com/228/avg-decimal-simplejson-decimal-is-not-json-serializable/comment-page-1#comment-502</link>
		<dc:creator>Ryan</dc:creator>
		<pubDate>Thu, 30 Sep 2010 20:56:59 +0000</pubDate>
		<guid isPermaLink="false">http://www.djangofoo.com/?p=228#comment-502</guid>
		<description>This solution truncates the decimal to and int value.  It would not give a very good answer unless you actually mean to call floor() on your decimal value.

A better solution would be to replace line 10:
return &quot;%d&quot; % obj
with
return obj.to_eng_string()

this way you still get a stringified version of your decimal, without rounding errors or forcing it to an integer.

Also, since simplejson 2.1.0, you can pass &#039;use_decimal=True&#039; to simplejson.dumps(), which will handle this for you without needing to add this handler.
django.utils, though, has 2.0.7 as of 1.2 , so this technique is still useful.</description>
		<content:encoded><![CDATA[<p>This solution truncates the decimal to and int value.  It would not give a very good answer unless you actually mean to call floor() on your decimal value.</p>
<p>A better solution would be to replace line 10:<br />
return &#8220;%d&#8221; % obj<br />
with<br />
return obj.to_eng_string()</p>
<p>this way you still get a stringified version of your decimal, without rounding errors or forcing it to an integer.</p>
<p>Also, since simplejson 2.1.0, you can pass &#8216;use_decimal=True&#8217; to simplejson.dumps(), which will handle this for you without needing to add this handler.<br />
django.utils, though, has 2.0.7 as of 1.2 , so this technique is still useful.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chamal</title>
		<link>http://www.djangofoo.com/228/avg-decimal-simplejson-decimal-is-not-json-serializable/comment-page-1#comment-224</link>
		<dc:creator>Chamal</dc:creator>
		<pubDate>Fri, 25 Jun 2010 09:59:13 +0000</pubDate>
		<guid isPermaLink="false">http://www.djangofoo.com/?p=228#comment-224</guid>
		<description>Nice simple trick for this Decimal problem I&#039;m facing too ;-)

thanks, that&#039;s much simplier than recoding an entire json serializer</description>
		<content:encoded><![CDATA[<p>Nice simple trick for this Decimal problem I&#8217;m facing too <img src='http://www.djangofoo.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p>thanks, that&#8217;s much simplier than recoding an entire json serializer</p>
]]></content:encoded>
	</item>
</channel>
</rss>

