javascript col计算

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript col计算相关的知识,希望对你有一定的参考价值。

const shares = 100
const buyPrice = 50
const sellPrice = 9
let buyingFee = 0
let sellingFee = 0

let buyCommision = (shares * buyPrice) * .0025
if (buyCommision < 20) {
   buyCommision = 20
}
const buyVAT = buyCommision * .12
const buyPTF = (shares * buyPrice) * .00005
const buySCCP = (shares * buyPrice) * .0001
buyingFee = buyCommision + buyVAT + buyPTF + buySCCP;
console.log('buyCommision', numberWithCommas(buyCommision))
console.log('total buying charges:', numberWithCommas(buyingFee))
let grossBuy = (shares * buyPrice) + buyingFee
console.log('gross buy:', numberWithCommas(grossBuy))


console.log('------------------------------------------------------------');


let sellCommision = (shares * sellPrice) * .0025
if (sellCommision < 20) {
   sellCommision = 20
}
const sellVAT = sellCommision * .12
const sellPTF = (shares * sellPrice) * .00005
const sellSCCP = (shares * sellPrice) * .0001
const sellSalesTax = (shares * sellPrice) * .006
sellingFee = sellCommision + sellVAT + sellPTF + sellSCCP + sellSalesTax;
console.log('sellCommision', numberWithCommas(sellCommision))
console.log('total selling charges:', numberWithCommas(sellingFee))

const grossSell = (shares * sellPrice) - sellingFee

console.log('gross sell:', numberWithCommas(grossSell))

console.log('------------------------------------------------------------');

console.log('PROFIT', grossSell - grossBuy);

const gain_loss = (grossSell - grossBuy) / grossBuy * 100

if (gain_loss < 0) {
   console.log('%Loss', gain_loss)
} else {
   console.log('%Gain', gain_loss)
}


function numberWithCommas(x) {
   var parts = x.toString().split(".");
   parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ",");
   return parts.join(".");
}

以上是关于javascript col计算的主要内容,如果未能解决你的问题,请参考以下文章

javascript 选择表-COL-上点击-ON-TD

如果我查询 Bigquery 视图,如何计算定价?

在 BigQuery 中计算不同的 concat

计算每行数据表中的唯一值

根据其他 col 值计算 col 的唯一出现次数[重复]

PostgreSQL:计算一行中包含值的列数