0

how to get the number, which is after the point in a float number in typescript. e.g.

2.3 I want to get 3 as return

user1938143
  • 1,022
  • 2
  • 22
  • 46

3 Answers3

0

Use the Split() method by converting the decimal value to String.

Gurdev Singh
  • 1,996
  • 13
  • 11
0

I will try with something simple like:

const num = 2.3;
const decimals = (num - Math.floor(num));​ // 0.3

so you get the integer part and then you subtract it from the original number in this way there's no need to do any string/number/string conversion

Plastic
  • 9,874
  • 6
  • 32
  • 53
0

To expand on Gurdevs answer

const num = 2.3
console.log(num.toString().split('.')[1])
JLai
  • 340
  • 1
  • 8