2

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

1ven
  • 6,776
  • 1
  • 25
  • 39

1 Answers1

1

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);
rejo
  • 3,352
  • 5
  • 27
  • 34