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