engineering notation literal "3e-3" turning into numbers in J

StackOverflow https://stackoverflow.com/questions/18277719

  •  24-06-2022
  •  | 
  •  

سؤال

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