[FIX] Number formatting on pages
* Added new global js library to convert number_format similar to PHP * Does some rounding, so not 100% perfect but does the trick * Added new library to master template * Updated dashboard to use this library for all numbers in question Fixes #1276
This commit is contained in:
parent
fcbf153bd9
commit
b82e500379
70
public/site_assets/global/js/number_format.js
Normal file
70
public/site_assets/global/js/number_format.js
Normal file
@ -0,0 +1,70 @@
|
||||
function number_format (number, decimals, dec_point, thousands_sep) {
|
||||
// From: http://phpjs.org/functions
|
||||
// + original by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
|
||||
// + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
|
||||
// + bugfix by: Michael White (http://getsprink.com)
|
||||
// + bugfix by: Benjamin Lupton
|
||||
// + bugfix by: Allan Jensen (http://www.winternet.no)
|
||||
// + revised by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
|
||||
// + bugfix by: Howard Yeend
|
||||
// + revised by: Luke Smith (http://lucassmith.name)
|
||||
// + bugfix by: Diogo Resende
|
||||
// + bugfix by: Rival
|
||||
// + input by: Kheang Hok Chin (http://www.distantia.ca/)
|
||||
// + improved by: davook
|
||||
// + improved by: Brett Zamir (http://brett-zamir.me)
|
||||
// + input by: Jay Klehr
|
||||
// + improved by: Brett Zamir (http://brett-zamir.me)
|
||||
// + input by: Amir Habibi (http://www.residence-mixte.com/)
|
||||
// + bugfix by: Brett Zamir (http://brett-zamir.me)
|
||||
// + improved by: Theriault
|
||||
// + input by: Amirouche
|
||||
// + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
|
||||
// * example 1: number_format(1234.56);
|
||||
// * returns 1: '1,235'
|
||||
// * example 2: number_format(1234.56, 2, ',', ' ');
|
||||
// * returns 2: '1 234,56'
|
||||
// * example 3: number_format(1234.5678, 2, '.', '');
|
||||
// * returns 3: '1234.57'
|
||||
// * example 4: number_format(67, 2, ',', '.');
|
||||
// * returns 4: '67,00'
|
||||
// * example 5: number_format(1000);
|
||||
// * returns 5: '1,000'
|
||||
// * example 6: number_format(67.311, 2);
|
||||
// * returns 6: '67.31'
|
||||
// * example 7: number_format(1000.55, 1);
|
||||
// * returns 7: '1,000.6'
|
||||
// * example 8: number_format(67000, 5, ',', '.');
|
||||
// * returns 8: '67.000,00000'
|
||||
// * example 9: number_format(0.9, 0);
|
||||
// * returns 9: '1'
|
||||
// * example 10: number_format('1.20', 2);
|
||||
// * returns 10: '1.20'
|
||||
// * example 11: number_format('1.20', 4);
|
||||
// * returns 11: '1.2000'
|
||||
// * example 12: number_format('1.2000', 3);
|
||||
// * returns 12: '1.200'
|
||||
// * example 13: number_format('1 000,50', 2, '.', ' ');
|
||||
// * returns 13: '100 050.00'
|
||||
// Strip all characters but numerical ones.
|
||||
number = (number + '').replace(/[^0-9+\-Ee.]/g, '');
|
||||
var n = !isFinite(+number) ? 0 : +number,
|
||||
prec = !isFinite(+decimals) ? 0 : Math.abs(decimals),
|
||||
sep = (typeof thousands_sep === 'undefined') ? ',' : thousands_sep,
|
||||
dec = (typeof dec_point === 'undefined') ? '.' : dec_point,
|
||||
s = '',
|
||||
toFixedFix = function (n, prec) {
|
||||
var k = Math.pow(10, prec);
|
||||
return '' + Math.round(n * k) / k;
|
||||
};
|
||||
// Fix for IE parseFloat(0.55).toFixed(0) = 0;
|
||||
s = (prec ? toFixedFix(n, prec) : '' + Math.round(n)).split('.');
|
||||
if (s[0].length > 3) {
|
||||
s[0] = s[0].replace(/\B(?=(?:\d{3})+(?!\d))/g, sep);
|
||||
}
|
||||
if ((s[1] || '').length < prec) {
|
||||
s[1] = s[1] || '';
|
||||
s[1] += new Array(prec - s[1].length + 1).join('0');
|
||||
}
|
||||
return s.join(dec);
|
||||
}
|
||||
@ -12,7 +12,7 @@
|
||||
<tbody>
|
||||
<tr>
|
||||
{foreach $SUMMARY as $type=>$total}
|
||||
<td class="right">{$total}</td>
|
||||
<td class="right">{$total|number_format:"8"}</td>
|
||||
{/foreach}
|
||||
</tr>
|
||||
</tbody>
|
||||
|
||||
@ -12,7 +12,7 @@
|
||||
<tbody>
|
||||
<tr>
|
||||
{foreach $SUMMARY as $type=>$total}
|
||||
<td class="right">{$total}</td>
|
||||
<td class="right">{$total|number_format:"8"}</td>
|
||||
{/foreach}
|
||||
</tr>
|
||||
</tbody>
|
||||
|
||||
@ -24,11 +24,11 @@
|
||||
</thead>
|
||||
<tr>
|
||||
<td align="left" style="font-weight: bold;">Confirmed</td>
|
||||
<td align="right"><span id="b-confirmed" class="confirmed" style="width: calc(80px); font-size: 12px;">{$GLOBAL.userdata.balance.confirmed}</span></td>
|
||||
<td align="right"><span id="b-confirmed" class="confirmed" style="width: calc(140px); font-size: 12px;">{$GLOBAL.userdata.balance.confirmed|number_format:"6"}</span></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="left" style="font-weight: bold;">Unconfirmed</td>
|
||||
<td align="right"><span id="b-unconfirmed" class="unconfirmed" style="width: calc(80px); font-size: 12px;">{$GLOBAL.userdata.balance.unconfirmed}</span></td>
|
||||
<td align="right"><span id="b-unconfirmed" class="unconfirmed" style="width: calc(140px); font-size: 12px;">{$GLOBAL.userdata.balance.unconfirmed|number_format:"6"}</span></td>
|
||||
</tr>
|
||||
</table>
|
||||
{if !$DISABLED_DASHBOARD and !$DISABLED_DASHBOARD_API}
|
||||
|
||||
@ -124,8 +124,8 @@ $(document).ready(function(){
|
||||
// Refresh balance information
|
||||
function refreshBalanceData(data) {
|
||||
balance = data.getuserbalance.data
|
||||
$('#b-confirmed').html(balance.confirmed);
|
||||
$('#b-unconfirmed').html(balance.unconfirmed);
|
||||
$('#b-confirmed').html(number_format(balance.confirmed, 6));
|
||||
$('#b-unconfirmed').html(number_format(balance.unconfirmed, 6));
|
||||
}
|
||||
|
||||
// Refresh other static numbers on the template
|
||||
@ -134,28 +134,28 @@ $(document).ready(function(){
|
||||
$('#b-dworkers').html(data.getdashboarddata.data.pool.workers);
|
||||
$('#b-hashrate').html((parseFloat(data.getdashboarddata.data.personal.hashrate).toFixed(2)));
|
||||
$('#b-sharerate').html((parseFloat(data.getdashboarddata.data.personal.sharerate).toFixed(2)));
|
||||
$('#b-yvalid').html(data.getdashboarddata.data.personal.shares.valid);
|
||||
$('#b-yivalid').html(data.getdashboarddata.data.personal.shares.invalid + " (" + data.getdashboarddata.data.personal.shares.invalid_percent + "%)" );
|
||||
$('#b-pvalid').html(data.getdashboarddata.data.pool.shares.valid);
|
||||
$('#b-pivalid').html(data.getdashboarddata.data.pool.shares.invalid + " (" + data.getdashboarddata.data.pool.shares.invalid_percent + "%)" );
|
||||
$('#b-diff').html(data.getdashboarddata.data.network.difficulty);
|
||||
$('#b-nextdiff').html(data.getdashboarddata.data.network.nextdifficulty + " (Change in " + data.getdashboarddata.data.network.blocksuntildiffchange + " Blocks)");
|
||||
$('#b-yvalid').html(number_format(data.getdashboarddata.data.personal.shares.valid));
|
||||
$('#b-yivalid').html(number_format(data.getdashboarddata.data.personal.shares.invalid) + " (" + data.getdashboarddata.data.personal.shares.invalid_percent + "%)" );
|
||||
$('#b-pvalid').html(number_format(data.getdashboarddata.data.pool.shares.valid));
|
||||
$('#b-pivalid').html(number_format(data.getdashboarddata.data.pool.shares.invalid) + " (" + data.getdashboarddata.data.pool.shares.invalid_percent + "%)" );
|
||||
$('#b-diff').html(number_format(data.getdashboarddata.data.network.difficulty, 8));
|
||||
$('#b-nextdiff').html(number_format(data.getdashboarddata.data.network.nextdifficulty, 8) + " (Change in " + data.getdashboarddata.data.network.blocksuntildiffchange + " Blocks)");
|
||||
$('#b-esttimeperblock').html(data.getdashboarddata.data.network.esttimeperblock + " seconds"); // <- this needs some nicer format
|
||||
$('#b-nblock').html(data.getdashboarddata.data.network.block);
|
||||
$('#b-target').html(data.getdashboarddata.data.pool.shares.estimated + " (done: " + data.getdashboarddata.data.pool.shares.progress + "%)" );
|
||||
$('#b-target').html(number_format(data.getdashboarddata.data.pool.shares.estimated) + " (done: " + data.getdashboarddata.data.pool.shares.progress + "%)" );
|
||||
{/literal}{if $GLOBAL.config.payout_system != 'pps'}{literal }
|
||||
$('#b-payout').html((parseFloat(data.getdashboarddata.data.personal.estimates.payout).toFixed(8)));
|
||||
$('#b-block').html((parseFloat(data.getdashboarddata.data.personal.estimates.block).toFixed(8)));
|
||||
$('#b-fee').html((parseFloat(data.getdashboarddata.data.personal.estimates.fee).toFixed(8)));
|
||||
$('#b-donation').html((parseFloat(data.getdashboarddata.data.personal.estimates.donation).toFixed(8)));
|
||||
$('#b-payout').html(number_format(data.getdashboarddata.data.personal.estimates.payout, 8));
|
||||
$('#b-block').html(number_format(data.getdashboarddata.data.personal.estimates.block, 8));
|
||||
$('#b-fee').html(number_format(data.getdashboarddata.data.personal.estimates.fee,8 ));
|
||||
$('#b-donation').html(number_format(data.getdashboarddata.data.personal.estimates.donation, 8));
|
||||
{/literal}{else}{literal}
|
||||
$('#b-ppsunpaid').html((parseFloat(data.getdashboarddata.data.personal.shares.unpaid).toFixed(0)));
|
||||
$('#b-ppsdiff').html((parseFloat(data.getdashboarddata.data.personal.sharedifficulty).toFixed(2)));
|
||||
$('#b-est1').html((parseFloat(data.getdashboarddata.data.personal.estimates.hours1).toFixed(8)));
|
||||
$('#b-est24hours').html((parseFloat(data.getdashboarddata.data.personal.estimates.hours24).toFixed(8)));
|
||||
$('#b-est7days').html((parseFloat(data.getdashboarddata.data.personal.estimates.days7).toFixed(8)));
|
||||
$('#b-est14days').html((parseFloat(data.getdashboarddata.data.personal.estimates.days14).toFixed(8)));
|
||||
$('#b-est30days').html((parseFloat(data.getdashboarddata.data.personal.estimates.days30).toFixed(8)));
|
||||
$('#b-ppsunpaid').html(number_format(data.getdashboarddata.data.personal.shares.unpaid));
|
||||
$('#b-ppsdiff').html(number_format(data.getdashboarddata.data.personal.sharedifficulty, 2));
|
||||
$('#b-est1').html(number_format(data.getdashboarddata.data.personal.estimates.hours1, 8));
|
||||
$('#b-est24hours').html(number_format(data.getdashboarddata.data.personal.estimates.hours24, 8));
|
||||
$('#b-est7days').html(number_format(data.getdashboarddata.data.personal.estimates.days7, 8));
|
||||
$('#b-est14days').html(number_format(data.getdashboarddata.data.personal.estimates.days14, 8));
|
||||
$('#b-est30days').html(number_format(data.getdashboarddata.data.personal.estimates.days30, 8));
|
||||
{/literal}{/if}{literal}
|
||||
{/literal}{if $GLOBAL.config.payout_system == 'pplns'}{literal}
|
||||
$('#b-pplns').html({/literal}{$GLOBAL.pplns.target}{literal});
|
||||
|
||||
@ -27,6 +27,7 @@
|
||||
<script type="text/javascript" src="{$PATH}/js/justgage.1.0.1.min.js"></script>
|
||||
<script type="text/javascript" src="{$PATH}/js/custom.js"></script>
|
||||
<script type="text/javascript" src="{$PATH}/js/tinybox.js"></script>
|
||||
<script type="text/javascript" src="{$PATH}/../global/js/number_format.js"></script>
|
||||
<!--[if IE]><script type="text/javascript" src="{$PATH}/js/excanvas.js"></script><![endif]-->
|
||||
|
||||
{if $GLOBAL.statistics.analytics.enabled}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user