0

How can I export first character to 1 character after "."

I've got data from API

{POWER : 1343.45}
{POWER : 15623.34577}
{POWER : 123.434}

I need just 123.4 from 123.45, 15623.3 from 15623.34577etc.

What should I do?

Reyhan
  • 19
  • 3
  • try to use split() see this https://stackoverflow.com/questions/25266372/splitting-a-string-at-special-character-with-javascript – shahin davoodi May 06 '23 at 09:32

1 Answers1

0

You can use regex and match() to solve this

const str = `{POWER : 1343.45}
 {POWER : 15623.34577}
 {POWER : 123.434}`
const reg = /\d+\.\d{1}/g
const result = str.match(reg) //["1343.4","15623.3","123.4"]
console.log(result)
Jason Tran
  • 11
  • 1