문제

I read a csv file in J, which has numbers in engineering notation, such as 3e-3.

In J, I can turn a literal into number by ".

". '3e3'
3000

and

". '3e_3'
0.003

But how to turn '3e-3' into 0.003

". '3e-3'
ill-formed number
도움이 되었습니까?

해결책

You can either guide ". by forcing it to evaluate to a number by giving it a default value:

0 ". '3e-3'

Or charsub the offending character:

'-_' charsub ". '3e-3'

I'd recommend the first, execution with ". is potentially dangerous, so forcing it to interpret numbers when that's what's desired is best practice.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top