From 072d8a17280d0bd16eedc269066fc0cb53ffbb68 Mon Sep 17 00:00:00 2001 From: Kukks Date: Thu, 10 Jan 2019 15:35:03 +0100 Subject: [PATCH] fix exponents in js product editor --- .../AppsPublic/Crowdfund/VueCrowdfund.cshtml | 4 +-- BTCPayServer/wwwroot/products/js/products.js | 28 +++++++++++++++---- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/BTCPayServer/Views/AppsPublic/Crowdfund/VueCrowdfund.cshtml b/BTCPayServer/Views/AppsPublic/Crowdfund/VueCrowdfund.cshtml index e3d448710..2c0e79482 100644 --- a/BTCPayServer/Views/AppsPublic/Crowdfund/VueCrowdfund.cshtml +++ b/BTCPayServer/Views/AppsPublic/Crowdfund/VueCrowdfund.cshtml @@ -32,13 +32,13 @@ :aria-valuenow="srvModel.info.progressPercentage" v-bind:style="{ width: srvModel.info.progressPercentage + '%' }" aria-valuemin="0" - v-b-tooltip :title="srvModel.info.progressPercentage + '% Confirmed Contributions'" + v-b-tooltip :title="parseFloat(srvModel.info.progressPercentage).toFixed(2) + '% confirmed contributions'" aria-valuemax="100">
diff --git a/BTCPayServer/wwwroot/products/js/products.js b/BTCPayServer/wwwroot/products/js/products.js index cc595badf..9c1c34cc1 100644 --- a/BTCPayServer/wwwroot/products/js/products.js +++ b/BTCPayServer/wwwroot/products/js/products.js @@ -29,7 +29,7 @@ Products.prototype.loadFromTemplate = function() { } if (productProperty.indexOf('price:') !== -1) { - price = parseFloat(productProperty.replace('price:', '').trim()); + price = parseFloat(productProperty.replace('price:', '').trim()).noExponents(); } if (productProperty.indexOf('title:') !== -1) { title = productProperty.replace('title:', '').trim(); @@ -68,13 +68,13 @@ Products.prototype.saveTemplate = function() { var product = this.products[key], id = product.id, title = product.title, - price = product.price, + price = product.price? product.price : 0, image = product.image description = product.description, custom = product.custom; template += id + '\n' + - ' price: ' + price + '\n' + + ' price: ' + parseFloat(price).noExponents() + '\n' + ' title: ' + title + '\n'; if (description) { @@ -158,7 +158,7 @@ Products.prototype.itemContent = function(index) { var template = this.template($('#template-product-content'), { 'id': product != null ? this.escape(product.id) : '', 'index': isNaN(index) ? '' : this.escape(index), - 'price': product != null ? this.escape(product.price) : '', + 'price': product != null ? parseFloat(this.escape(product.price)).noExponents() : '', 'title': product != null ? this.escape(product.title) : '', 'description': product != null ? this.escape(product.description) : '', 'image': product != null ? this.escape(product.image) : '', @@ -183,4 +183,22 @@ Products.prototype.escape = function(input) { .replace(//g, '>') ; -} \ No newline at end of file +} + +Number.prototype.noExponents= function(){ + var data= String(this).split(/[eE]/); + if(data.length== 1) return data[0]; + + var z= '', sign= this<0? '-':'', + str= data[0].replace('.', ''), + mag= Number(data[1])+ 1; + + if(mag<0){ + z= sign + '0.'; + while(mag++) z += '0'; + return z + str.replace(/^\-/,''); + } + mag -= str.length; + while(mag--) z += '0'; + return str + z; +};