Regular: how to match content after 2 decimal places

// 2

var s = "12.34567"     
//  12.34
console.log(s.replace(/\.\d{2}/, "*")) // 12*567
console.log(s.replace(/\.[^\d]{2}\d+/, "*")) // 12.34567

var s = '12.34567';
var num = Number (s.match (/ ^ d + (?: .d {0jue 2})? /)
alert (num); / / 12.34

rounding:
var s = 12.34567
alert (s.toFixed (2)); / / 12.35

)
/^(\d+\.\d{2})(\d+)$/.test(12.34567)
true
RegExp.$2
"567"

clipboard.png


1. No regularization

new Number('12.34567').toFixed(2);
(+'12.34567').toFixed(2);
var s='12.34567';
s.substring(0,s.indexOf(".")+3);

II. Use regularization

'12.34567'.match(/^\d+\.\d{2}/)[0];
'12.34567'.replace(/^(\d+\.\d{2})\d*$/,"$1");
Menu