JSFiddle - React, Tailwind, and code Playground

by funato

HTML

<p>1,280円の税込み価格は</p>
<script type="text/javascript">
var Price= function(price){
	this.tax;
	this.price=price;
	this.addTax=function(){
		this.price+=Math.round(this.price*this.tax/100);
	}
this.format=function(){
var s=new String(this.price);
	var ret='';
	
	for (var i=s.length-3; i>0; i-=3){
		ret=','+s.substr(i,3)+ret;
	}
	ret=s.substr(0,i+3)+ret;
	
	return ret;	
}
}
var thisPrice=new Price(1280);
thisPrice.tax=5; // 消費税は5%
thisPrice.addTax();
document.write(thisPrice.format())

	</script>
    円です。</p>