Вопрос

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