MoreBloodWine (OP)
Legendary
Offline
Activity: 1050
Merit: 1001
|
|
January 29, 2014, 04:59:14 PM |
|
Trying to finish up some work to display BTC info on my site but this damn rounding up that number_format() does is driving me nuts. Anyone know what I need to do to sop the rounding up but still get he x.xx result ?
$formatted_blockchain_wallet_bal = number_format( $unmodified_blockchain_balance, 2 );
|
To be decided...
|
|
|
|
|
|
|
Whoever mines the block which ends up containing your transaction will get its fee.
|
|
|
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
|
|
|
|
Bitsky
|
|
January 29, 2014, 09:51:49 PM |
|
A simple way: $formatted_blockchain_wallet_bal = intval($unmodified_blockchain_balance * 100) / 100; Or if you want to make it look odd: $formatted_blockchain_wallet_bal = substr($unmodified_blockchain_balance, 0, strpos($unmodified_blockchain_balance, '.') + 3);
|
|
|
|
MoreBloodWine (OP)
Legendary
Offline
Activity: 1050
Merit: 1001
|
|
January 29, 2014, 11:33:43 PM |
|
A simple way: $formatted_blockchain_wallet_bal = intval($unmodified_blockchain_balance * 100) / 100; Or if you want to make it look odd: $formatted_blockchain_wallet_bal = substr($unmodified_blockchain_balance, 0, strpos($unmodified_blockchain_balance, '.') + 3); Thx for that but eve though it's at 0 now it doesn' display as x.xx like with number format. Like right now my final nalance is 0.01686725, well the code would ideally display 0.00 and then when I get another 0.004 the ode would / should disaply 0.01.
|
To be decided...
|
|
|
Bitsky
|
|
January 31, 2014, 09:36:29 AM |
|
$formatted_blockchain_wallet_bal = sprintf('%02d', $formatted_blockchain_wallet_bal);
|
|
|
|
MoreBloodWine (OP)
Legendary
Offline
Activity: 1050
Merit: 1001
|
|
January 31, 2014, 09:51:02 AM |
|
I forgot all abou this post and sor of went a differen route with the same results. ### Blockchain Balance ### $unmodified_blockchain_balance = ( $blockchain_final_balance / 100000000 ); $blockchain_wallet_bal = substr( sprintf( '%.8f', $unmodified_blockchain_balance ), 0, -9 ); ### Blockchain Str Length ### $blockchain_str = $blockchain_wallet_bal; $blockchain_str_length = strlen($blockchain_str); ### Blockchain Balance Visuals ### $formatted_blockchain_wallet_bal1 = number_format( $blockchain_wallet_bal ); // Everything beofore the decimal. $formatted_blockchain_wallet_bal2 = substr( sprintf( '%.8f', $unmodified_blockchain_balance ), $blockchain_str_length, -6 ); // The decimal & two trailing digits. $formatted_small_blockchain_wallet_bal = substr( sprintf( '%.8f', $unmodified_blockchain_balance ), -6 ); // Just the last 6 digits.
I know it's a little over complaicated or w/e but it works ;-)
|
To be decided...
|
|
|
Bitsky
|
|
January 31, 2014, 10:49:45 AM |
|
If you only want a formatting like 0.00 without rounding, that code is about an order of magnitude slower.
|
|
|
|
MoreBloodWine (OP)
Legendary
Offline
Activity: 1050
Merit: 1001
|
|
January 31, 2014, 11:40:26 AM |
|
If you only want a formatting like 0.00 without rounding, that code is about an order of magnitude slower.
I don't only want the x.xx, I use the last six digits for smaller txt. The way everything is set, I get my smaller txt and get to numberformat for the commas without rounding the decimal.
|
To be decided...
|
|
|
Bitsky
|
|
January 31, 2014, 02:28:35 PM |
|
You can do that in a oneliner: $formatted = preg_replace('/^(\d+\.\d\d)(\d+)/', "$1<small>$2</small>", $unmodified_blockchain_balance);
|
|
|
|
MoreBloodWine (OP)
Legendary
Offline
Activity: 1050
Merit: 1001
|
|
January 31, 2014, 03:38:38 PM |
|
You can do that in a oneliner: $formatted = preg_replace('/^(\d+\.\d\d)(\d+)/', "$1<small>$2</small>", $unmodified_blockchain_balance); That works like a charm but with one small flaw. I added 1234 to he value and get this. 1234.00686725 No comma, so unless your code can be modified to add he comma at the appropriate spots even say at 1000000 then it looks like I'll have to stick with the multiple lines I use. Really liked your sugestion too. ---------------------------------------------------------------------------------------------------------------------------------------------- Want a sig like mine for your BTC Guild stats, then check out this post !
|
To be decided...
|
|
|
Bitsky
|
|
January 31, 2014, 08:21:12 PM |
|
That works like a charm but with one small flaw.
I added 1234 to he value and get this.
1234.00686725
No comma, so unless your code can be modified to add he comma at the appropriate spots even say at 1000000 then it looks like I'll have to stick with the multiple lines I use. Really liked your sugestion too.
Like that? $formatted = preg_replace('/^([\d,]+\.\d\d)(\d+)/', "$1<small>$2</small>", number_format($unmodified_blockchain_balance, 8)); PS: If you ever reach those 1000000, give me a few
|
|
|
|
MoreBloodWine (OP)
Legendary
Offline
Activity: 1050
Merit: 1001
|
|
January 31, 2014, 10:37:17 PM |
|
That works like a charm but with one small flaw.
I added 1234 to he value and get this.
1234.00686725
No comma, so unless your code can be modified to add he comma at the appropriate spots even say at 1000000 then it looks like I'll have to stick with the multiple lines I use. Really liked your sugestion too.
Like that? $formatted = preg_replace('/^([\d,]+\.\d\d)(\d+)/', "$1<small>$2</small>", number_format($unmodified_blockchain_balance, 8)); PS: If you ever reach those 1000000, give me a few Exactly like that n ya, ill hook you up with 0.00000001 ;-p Thx !
|
To be decided...
|
|
|
Bitsky
|
|
January 31, 2014, 11:56:25 PM |
|
Exactly like that n ya, ill hook you up with 0.00000001 ;-p
Thx !
1 Satoshi? Not sure if thrilled.
|
|
|
|
MoreBloodWine (OP)
Legendary
Offline
Activity: 1050
Merit: 1001
|
|
February 01, 2014, 12:01:41 AM |
|
Exactly like that n ya, ill hook you up with 0.00000001 ;-p
Thx !
1 Satoshi? Not sure if thrilled. Oh wait, that was backwards 10000000.0 Better ;-P But seriously, thx !
|
To be decided...
|
|
|
|