<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://en.bitcoin.it/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Sdfdsafsaff</id>
	<title>Bitcoin Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://en.bitcoin.it/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Sdfdsafsaff"/>
	<link rel="alternate" type="text/html" href="https://en.bitcoin.it/wiki/Special:Contributions/Sdfdsafsaff"/>
	<updated>2026-04-23T13:39:03Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.43.8</generator>
	<entry>
		<id>https://en.bitcoin.it/w/index.php?title=Proper_Money_Handling_(JSON-RPC)&amp;diff=10318</id>
		<title>Proper Money Handling (JSON-RPC)</title>
		<link rel="alternate" type="text/html" href="https://en.bitcoin.it/w/index.php?title=Proper_Money_Handling_(JSON-RPC)&amp;diff=10318"/>
		<updated>2011-06-11T01:57:12Z</updated>

		<summary type="html">&lt;p&gt;Sdfdsafsaff: /* Common Lisp */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Overview ==&lt;br /&gt;
The original bitcoin client stores all bitcoin values as 64-bit integers, with 1 BTC stored as 100,000,000 (one-hundred-million of the smallest possible bitcoin unit).  Values are expressed as double-precision Numbers in the JSON API, with 1 BTC expressed as 1.00000000&lt;br /&gt;
&lt;br /&gt;
If you are writing software that uses the JSON-RPC interface you need to be aware of possible floating-point conversion issues.  You, or the JSON library you are using, should convert amounts to either a fixed-point Decimal representation (with 8 digits after the decimal point) or ideally a 64-bit integer representation. In either case, rounding values is required.&lt;br /&gt;
&lt;br /&gt;
Improper value handling can lead to embarrassing errors; for example, if you truncate instead of doing proper rounding and your software will display the value &amp;quot;0.1 BTC&amp;quot; as &amp;quot;0.09999999 BTC&amp;quot; (or, worse, &amp;quot;0.09 BTC&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
The original bitcoin client does proper, full-precision rounding for all values passed to it via the RPC interface.  So, for example, if the value 0.1 is converted to the value &amp;quot;0.099999999999&amp;quot; by your JSON-RPC library, that value will be rounded to the nearest 0.00000001 bitcoin and will be treated as exactly 0.1 bitcoins.&lt;br /&gt;
&lt;br /&gt;
The rest of this page gives sample code for various JSON libraries and programming languages.&lt;br /&gt;
&lt;br /&gt;
== BASH ==&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
 function JSONtoAmount() {&lt;br /&gt;
     printf &#039;%.8f&#039; &amp;quot;$1&amp;quot; | tr -d &#039;.&#039;&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== C/C++ ==&lt;br /&gt;
C/C++ JSON libraries return the JavaScript Number type as type &#039;double&#039;.  To convert, without loss of precision, from a double to a 64-bit integer multiply by 100,000,000 and round to the nearest integer:&lt;br /&gt;
 int64_t JSONtoAmount(double value) {&lt;br /&gt;
     return (int64_t)(value * 1e8 + (value &amp;lt; 0.0 ? -.5 : .5));&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
To convert to a JSON value divide by 100,000,000.0, and make sure your JSON implementation outputs doubles with 8 or more digits after the decimal point:&lt;br /&gt;
  double forJSON = (double)amount / 1e8;&lt;br /&gt;
&lt;br /&gt;
== ECMAScript ==&lt;br /&gt;
&lt;br /&gt;
 function JSONtoAmount(value) {&lt;br /&gt;
     return amount = Math.round(1e8 * value);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
== Perl ==&lt;br /&gt;
 sub JSONtoAmount {&lt;br /&gt;
     return sprintf &#039;%.0f&#039;, 1e8 * shift;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
== PHP ==&lt;br /&gt;
 function JSONtoAmount($value) {&lt;br /&gt;
     return round(value * 1e8);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
== Python ==&lt;br /&gt;
 def JSONtoAmount(value):&lt;br /&gt;
     return long(round(value * 1e8))&lt;br /&gt;
 def AmountToJSON(amount):&lt;br /&gt;
     return float(amount / 1e8)&lt;br /&gt;
&lt;br /&gt;
== Common Lisp ==&lt;br /&gt;
  (defun json-to-amount (n)&lt;br /&gt;
    (coerce (round (* n 1e8)) &#039;integer))&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;CAUTION&#039;&#039;&#039;: The CL-JSON library parses numbers as &#039;&#039;single&#039;&#039; precision floating-point by&lt;br /&gt;
default. The default parsing behavior can be overridden as follows:&lt;br /&gt;
&lt;br /&gt;
   (set-custom-vars :real (lambda (n)&lt;br /&gt;
                             (json::parse-number (concatenate &#039;string n &amp;quot;d0&amp;quot;))))&lt;br /&gt;
[[Category:Technical]]&lt;br /&gt;
[[Category:Developer]]&lt;/div&gt;</summary>
		<author><name>Sdfdsafsaff</name></author>
	</entry>
	<entry>
		<id>https://en.bitcoin.it/w/index.php?title=Proper_Money_Handling_(JSON-RPC)&amp;diff=10317</id>
		<title>Proper Money Handling (JSON-RPC)</title>
		<link rel="alternate" type="text/html" href="https://en.bitcoin.it/w/index.php?title=Proper_Money_Handling_(JSON-RPC)&amp;diff=10317"/>
		<updated>2011-06-11T01:56:38Z</updated>

		<summary type="html">&lt;p&gt;Sdfdsafsaff: /* Common Lisp */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Overview ==&lt;br /&gt;
The original bitcoin client stores all bitcoin values as 64-bit integers, with 1 BTC stored as 100,000,000 (one-hundred-million of the smallest possible bitcoin unit).  Values are expressed as double-precision Numbers in the JSON API, with 1 BTC expressed as 1.00000000&lt;br /&gt;
&lt;br /&gt;
If you are writing software that uses the JSON-RPC interface you need to be aware of possible floating-point conversion issues.  You, or the JSON library you are using, should convert amounts to either a fixed-point Decimal representation (with 8 digits after the decimal point) or ideally a 64-bit integer representation. In either case, rounding values is required.&lt;br /&gt;
&lt;br /&gt;
Improper value handling can lead to embarrassing errors; for example, if you truncate instead of doing proper rounding and your software will display the value &amp;quot;0.1 BTC&amp;quot; as &amp;quot;0.09999999 BTC&amp;quot; (or, worse, &amp;quot;0.09 BTC&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
The original bitcoin client does proper, full-precision rounding for all values passed to it via the RPC interface.  So, for example, if the value 0.1 is converted to the value &amp;quot;0.099999999999&amp;quot; by your JSON-RPC library, that value will be rounded to the nearest 0.00000001 bitcoin and will be treated as exactly 0.1 bitcoins.&lt;br /&gt;
&lt;br /&gt;
The rest of this page gives sample code for various JSON libraries and programming languages.&lt;br /&gt;
&lt;br /&gt;
== BASH ==&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
 function JSONtoAmount() {&lt;br /&gt;
     printf &#039;%.8f&#039; &amp;quot;$1&amp;quot; | tr -d &#039;.&#039;&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== C/C++ ==&lt;br /&gt;
C/C++ JSON libraries return the JavaScript Number type as type &#039;double&#039;.  To convert, without loss of precision, from a double to a 64-bit integer multiply by 100,000,000 and round to the nearest integer:&lt;br /&gt;
 int64_t JSONtoAmount(double value) {&lt;br /&gt;
     return (int64_t)(value * 1e8 + (value &amp;lt; 0.0 ? -.5 : .5));&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
To convert to a JSON value divide by 100,000,000.0, and make sure your JSON implementation outputs doubles with 8 or more digits after the decimal point:&lt;br /&gt;
  double forJSON = (double)amount / 1e8;&lt;br /&gt;
&lt;br /&gt;
== ECMAScript ==&lt;br /&gt;
&lt;br /&gt;
 function JSONtoAmount(value) {&lt;br /&gt;
     return amount = Math.round(1e8 * value);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
== Perl ==&lt;br /&gt;
 sub JSONtoAmount {&lt;br /&gt;
     return sprintf &#039;%.0f&#039;, 1e8 * shift;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
== PHP ==&lt;br /&gt;
 function JSONtoAmount($value) {&lt;br /&gt;
     return round(value * 1e8);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
== Python ==&lt;br /&gt;
 def JSONtoAmount(value):&lt;br /&gt;
     return long(round(value * 1e8))&lt;br /&gt;
 def AmountToJSON(amount):&lt;br /&gt;
     return float(amount / 1e8)&lt;br /&gt;
&lt;br /&gt;
== Common Lisp ==&lt;br /&gt;
  (defun json-to-amount (n)&lt;br /&gt;
    (coerce (round (* n 1e8)) &#039;integer))&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;CAUTION&#039;&#039;&#039;: The CL-JSON library parses numbers as &#039;&#039;single&#039;&#039; precision floating-point by&lt;br /&gt;
default, costing you precision. The default parsing behavior can be overridden as follows:&lt;br /&gt;
&lt;br /&gt;
   (set-custom-vars :real (lambda (n)&lt;br /&gt;
                             (json::parse-number (concatenate &#039;string n &amp;quot;d0&amp;quot;))))&lt;br /&gt;
[[Category:Technical]]&lt;br /&gt;
[[Category:Developer]]&lt;/div&gt;</summary>
		<author><name>Sdfdsafsaff</name></author>
	</entry>
	<entry>
		<id>https://en.bitcoin.it/w/index.php?title=Talk:Proper_Money_Handling_(JSON-RPC)&amp;diff=10301</id>
		<title>Talk:Proper Money Handling (JSON-RPC)</title>
		<link rel="alternate" type="text/html" href="https://en.bitcoin.it/w/index.php?title=Talk:Proper_Money_Handling_(JSON-RPC)&amp;diff=10301"/>
		<updated>2011-06-10T23:15:16Z</updated>

		<summary type="html">&lt;p&gt;Sdfdsafsaff: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;RE: best practices in ECMAScript:&lt;br /&gt;
Just converting to base units doesn&#039;t magically fix the issues; if I have 1.0BTC == 100000000.0 base units and I need to divide that value into three equal pieces, I&#039;m going to run into issues whether the result is 0.3333333.... or 3333333.33333...&lt;br /&gt;
&lt;br /&gt;
And the fixes are the same:  either round to the nearest .0000001 or to the nearest 1 before display, etc.&lt;br /&gt;
&lt;br /&gt;
::The real solution is not to write money-handling code in ECMAScript. [[User:Sdfdsafsaff|Sdfdsafsaff]] 23:15, 10 June 2011 (GMT)&lt;br /&gt;
&lt;br /&gt;
For Ruby I think the syntax is:&lt;br /&gt;
&lt;br /&gt;
(f * 1e8).round.to_f / 1e8&lt;br /&gt;
&lt;br /&gt;
Correct?&lt;br /&gt;
&lt;br /&gt;
== ECMAScript? ==&lt;br /&gt;
&lt;br /&gt;
Since the value is already in ECMAScript&#039;s native representation, why would you use a conversion function?&lt;/div&gt;</summary>
		<author><name>Sdfdsafsaff</name></author>
	</entry>
	<entry>
		<id>https://en.bitcoin.it/w/index.php?title=Talk:Proper_Money_Handling_(JSON-RPC)&amp;diff=10300</id>
		<title>Talk:Proper Money Handling (JSON-RPC)</title>
		<link rel="alternate" type="text/html" href="https://en.bitcoin.it/w/index.php?title=Talk:Proper_Money_Handling_(JSON-RPC)&amp;diff=10300"/>
		<updated>2011-06-10T23:14:20Z</updated>

		<summary type="html">&lt;p&gt;Sdfdsafsaff: /* ECMAScript? */ new section&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;RE: best practices in ECMAScript:&lt;br /&gt;
Just converting to base units doesn&#039;t magically fix the issues; if I have 1.0BTC == 100000000.0 base units and I need to divide that value into three equal pieces, I&#039;m going to run into issues whether the result is 0.3333333.... or 3333333.33333...&lt;br /&gt;
&lt;br /&gt;
And the fixes are the same:  either round to the nearest .0000001 or to the nearest 1 before display, etc.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For Ruby I think the syntax is:&lt;br /&gt;
&lt;br /&gt;
(f * 1e8).round.to_f / 1e8&lt;br /&gt;
&lt;br /&gt;
Correct?&lt;br /&gt;
&lt;br /&gt;
== ECMAScript? ==&lt;br /&gt;
&lt;br /&gt;
Since the value is already in ECMAScript&#039;s native representation, why would you use a conversion function?&lt;/div&gt;</summary>
		<author><name>Sdfdsafsaff</name></author>
	</entry>
	<entry>
		<id>https://en.bitcoin.it/w/index.php?title=Proper_Money_Handling_(JSON-RPC)&amp;diff=10299</id>
		<title>Proper Money Handling (JSON-RPC)</title>
		<link rel="alternate" type="text/html" href="https://en.bitcoin.it/w/index.php?title=Proper_Money_Handling_(JSON-RPC)&amp;diff=10299"/>
		<updated>2011-06-10T23:09:34Z</updated>

		<summary type="html">&lt;p&gt;Sdfdsafsaff: /* Common Lisp */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Overview ==&lt;br /&gt;
The original bitcoin client stores all bitcoin values as 64-bit integers, with 1 BTC stored as 100,000,000 (one-hundred-million of the smallest possible bitcoin unit).  Values are expressed as double-precision Numbers in the JSON API, with 1 BTC expressed as 1.00000000&lt;br /&gt;
&lt;br /&gt;
If you are writing software that uses the JSON-RPC interface you need to be aware of possible floating-point conversion issues.  You, or the JSON library you are using, should convert amounts to either a fixed-point Decimal representation (with 8 digits after the decimal point) or ideally a 64-bit integer representation. In either case, rounding values is required.&lt;br /&gt;
&lt;br /&gt;
Improper value handling can lead to embarrassing errors; for example, if you truncate instead of doing proper rounding and your software will display the value &amp;quot;0.1 BTC&amp;quot; as &amp;quot;0.09999999 BTC&amp;quot; (or, worse, &amp;quot;0.09 BTC&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
The original bitcoin client does proper, full-precision rounding for all values passed to it via the RPC interface.  So, for example, if the value 0.1 is converted to the value &amp;quot;0.099999999999&amp;quot; by your JSON-RPC library, that value will be rounded to the nearest 0.00000001 bitcoin and will be treated as exactly 0.1 bitcoins.&lt;br /&gt;
&lt;br /&gt;
The rest of this page gives sample code for various JSON libraries and programming languages.&lt;br /&gt;
&lt;br /&gt;
== BASH ==&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
 function JSONtoAmount() {&lt;br /&gt;
     printf &#039;%.8f&#039; &amp;quot;$1&amp;quot; | tr -d &#039;.&#039;&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== C/C++ ==&lt;br /&gt;
C/C++ JSON libraries return the JavaScript Number type as type &#039;double&#039;.  To convert, without loss of precision, from a double to a 64-bit integer multiply by 100,000,000 and round to the nearest integer:&lt;br /&gt;
 int64_t JSONtoAmount(double value) {&lt;br /&gt;
     return (int64_t)(value * 1e8 + (value &amp;lt; 0.0 ? -.5 : .5));&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
To convert to a JSON value divide by 100,000,000.0, and make sure your JSON implementation outputs doubles with 8 or more digits after the decimal point:&lt;br /&gt;
  double forJSON = (double)amount / 1e8;&lt;br /&gt;
&lt;br /&gt;
== ECMAScript ==&lt;br /&gt;
&lt;br /&gt;
 function JSONtoAmount(value) {&lt;br /&gt;
     return amount = Math.round(1e8 * value);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
== Perl ==&lt;br /&gt;
 sub JSONtoAmount {&lt;br /&gt;
     return sprintf &#039;%.0f&#039;, 1e8 * shift;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
== PHP ==&lt;br /&gt;
 function JSONtoAmount($value) {&lt;br /&gt;
     return round(value * 1e8);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
== Python ==&lt;br /&gt;
 def JSONtoAmount(value):&lt;br /&gt;
     return long(round(value * 1e8))&lt;br /&gt;
 def AmountToJSON(amount):&lt;br /&gt;
     return float(amount / 1e8)&lt;br /&gt;
&lt;br /&gt;
== Common Lisp ==&lt;br /&gt;
  (defun json-to-amount (n)&lt;br /&gt;
    (coerce (round (* n 1e8)) &#039;integer))&lt;br /&gt;
&lt;br /&gt;
[[Category:Technical]]&lt;br /&gt;
[[Category:Developer]]&lt;/div&gt;</summary>
		<author><name>Sdfdsafsaff</name></author>
	</entry>
	<entry>
		<id>https://en.bitcoin.it/w/index.php?title=Proper_Money_Handling_(JSON-RPC)&amp;diff=10298</id>
		<title>Proper Money Handling (JSON-RPC)</title>
		<link rel="alternate" type="text/html" href="https://en.bitcoin.it/w/index.php?title=Proper_Money_Handling_(JSON-RPC)&amp;diff=10298"/>
		<updated>2011-06-10T23:09:18Z</updated>

		<summary type="html">&lt;p&gt;Sdfdsafsaff: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Overview ==&lt;br /&gt;
The original bitcoin client stores all bitcoin values as 64-bit integers, with 1 BTC stored as 100,000,000 (one-hundred-million of the smallest possible bitcoin unit).  Values are expressed as double-precision Numbers in the JSON API, with 1 BTC expressed as 1.00000000&lt;br /&gt;
&lt;br /&gt;
If you are writing software that uses the JSON-RPC interface you need to be aware of possible floating-point conversion issues.  You, or the JSON library you are using, should convert amounts to either a fixed-point Decimal representation (with 8 digits after the decimal point) or ideally a 64-bit integer representation. In either case, rounding values is required.&lt;br /&gt;
&lt;br /&gt;
Improper value handling can lead to embarrassing errors; for example, if you truncate instead of doing proper rounding and your software will display the value &amp;quot;0.1 BTC&amp;quot; as &amp;quot;0.09999999 BTC&amp;quot; (or, worse, &amp;quot;0.09 BTC&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
The original bitcoin client does proper, full-precision rounding for all values passed to it via the RPC interface.  So, for example, if the value 0.1 is converted to the value &amp;quot;0.099999999999&amp;quot; by your JSON-RPC library, that value will be rounded to the nearest 0.00000001 bitcoin and will be treated as exactly 0.1 bitcoins.&lt;br /&gt;
&lt;br /&gt;
The rest of this page gives sample code for various JSON libraries and programming languages.&lt;br /&gt;
&lt;br /&gt;
== BASH ==&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
 function JSONtoAmount() {&lt;br /&gt;
     printf &#039;%.8f&#039; &amp;quot;$1&amp;quot; | tr -d &#039;.&#039;&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== C/C++ ==&lt;br /&gt;
C/C++ JSON libraries return the JavaScript Number type as type &#039;double&#039;.  To convert, without loss of precision, from a double to a 64-bit integer multiply by 100,000,000 and round to the nearest integer:&lt;br /&gt;
 int64_t JSONtoAmount(double value) {&lt;br /&gt;
     return (int64_t)(value * 1e8 + (value &amp;lt; 0.0 ? -.5 : .5));&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
To convert to a JSON value divide by 100,000,000.0, and make sure your JSON implementation outputs doubles with 8 or more digits after the decimal point:&lt;br /&gt;
  double forJSON = (double)amount / 1e8;&lt;br /&gt;
&lt;br /&gt;
== ECMAScript ==&lt;br /&gt;
&lt;br /&gt;
 function JSONtoAmount(value) {&lt;br /&gt;
     return amount = Math.round(1e8 * value);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
== Perl ==&lt;br /&gt;
 sub JSONtoAmount {&lt;br /&gt;
     return sprintf &#039;%.0f&#039;, 1e8 * shift;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
== PHP ==&lt;br /&gt;
 function JSONtoAmount($value) {&lt;br /&gt;
     return round(value * 1e8);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
== Python ==&lt;br /&gt;
 def JSONtoAmount(value):&lt;br /&gt;
     return long(round(value * 1e8))&lt;br /&gt;
 def AmountToJSON(amount):&lt;br /&gt;
     return float(amount / 1e8)&lt;br /&gt;
&lt;br /&gt;
== Common Lisp ==&lt;br /&gt;
(defun json-to-amount (n)&lt;br /&gt;
  (coerce (round (* n 1e8)) &#039;integer))&lt;br /&gt;
&lt;br /&gt;
[[Category:Technical]]&lt;br /&gt;
[[Category:Developer]]&lt;/div&gt;</summary>
		<author><name>Sdfdsafsaff</name></author>
	</entry>
</feed>