JSFiddle - React, Tailwind, and code Playground

by helgatheviking

JavaScript

var sep = '.';

var v = 50.000000;
var regex = '/' + sep + '0+/g';

//console.log(v.toString().replace(regex, ''));

var trim_zeros = 'yes';
var decimals = 2;
var remove = '.';

var price = '10.50';

if ( trim_zeros === 'yes' && decimals > 0 ) {
		for (var i = 0; i < decimals; i++) { remove = remove + '0'; }
		price = price.replace( remove, '' );
	}
  
 console.log(price);