William Grimsley
William Grimsley

Reputation: 47

Print ".00" When The Result Is A Whole Number?

I want to try and print ".00" after the variables cache.todayHigh and cache.todayLow are whole numbers.

if (ddimgtooltip.showTips) {
  // update tooltip
  tip = 'High ' + strings.baro_info + ': ' + cache.todayHigh + ' ' + data.pressunit + ' ' + strings.at + ' ' + data.TpressTH +
  ' <br> ' + strings.minimum_info + ' ' + strings.baro_info + ': ' + cache.todayLow + ' ' + data.pressunit + ' ' + strings.at + ' ' + data.TpressTL;

  if (cache.trendVal !== -9999) {
    tip +=  '<br>' + strings.baro_trend_info + ': ' + baroTrend(cache.trendVal, data.pressunit, true) + ' ' +
    (cache.trendValRnd > 0 ? '' : '') + cache.trendValRnd + ' ' + data.pressunit + '/hr';
  }

  $('#imgtip5_txt').html(tip);
}

e.g. 1017 hPa to 1017.00 hPa.

Is this possible?

Thanks,

William

Upvotes: 2

Views: 58

Answers (1)

rejo
rejo

Reputation: 3350

Try this,

var yvalue = '1702 hpa';
var num = yvalue.replace(/[^0-9]+/ig,"");
value = Number(num).toFixed(2);
var fvalue=  value +' '+yvalue.split(' ')[1]
console.log(fvalue);

Upvotes: 1

Related Questions