Advertise with us (we do not endorse any site advertised)

Author Topic: [zelles] PHP functions for Bitcoin Numbers  (Read 7142 times)

0 Members and 1 Guest are viewing this topic.

Offline zellesTopic starter

  • Newbie
  • Joined: May 2013
  • Posts: 21
  • Country: 00
  • Karma: +2/-0
  • Unleaded Only
    • View Profile
  • Bitcoin Address: 13NEL6H4djo3ECiQnwpKeC5ceEx2iCdSXZ
[zelles] PHP functions for Bitcoin Numbers
« on: May 21, 2013, 03:45:08 AM »
Some simple PHP functions to help format numbers used as Bitcoin amounts and balances. Main usage is after doing math with 2 Bitcoin amounts. It prevents the output from showing those annoying scientific notations like 1.0E-6

A function to modify a number to bitcoin format
Example: 0.00120000
Code: [Select]
function satoshitize($satoshitize) {
return sprintf("%.8f", $satoshitize);
}

A function to trim trailing zeroes and decimal if wanted after satoshitizing a number
Examples:
10.00023100 = 10.000231
1.000 = 1
10.000 = 10
Code: [Select]
function satoshitrim($satoshitrim) {
return rtrim(rtrim($satoshitrim, "0"), ".");
}

Example usage:
Code: [Select]
$Amount_To_Clean = "0.0234045395636709999";

$Amount_of_Bitcoin = satoshitrim(satoshitize($Amount_To_Clean));

echo $Amount_of_Bitcoin;
The above would output 0.02340453
« Last Edit: May 21, 2013, 03:47:14 AM by zelles »
Hire zelles for your next project.


 

[zelles] WalletScript, A opensource PHP wallet script for Bitcoin and most alts

Started by zelles

Replies: 3
Views: 13377
Last post December 09, 2013, 07:49:22 AM
by dick
PHP API Connector for http://bitcoin-24.com

Started by pangu

Replies: 2
Views: 7747
Last post April 01, 2013, 08:14:11 AM
by gweedo
[zelles] opensource Bitcoin exchange website script

Started by zelles

Replies: 19
Views: 50477
Last post July 09, 2017, 02:50:26 PM
by Key
Bitcoin+faucet

Started by iBits

Replies: 6
Views: 12320
Last post July 23, 2013, 01:39:06 PM
by Obituary
My Bitcoin master thesis

Started by ThePiachu

Replies: 2
Views: 13385
Last post December 04, 2012, 10:55:47 PM
by cryptoanarchist

your ads here