2

I want to convert the value from 1.759114e-07 to 175.9114e-09. How can I script the conversion?

I tried this but I'm not getting what I want (which is 175.9114e-09):

$ echo 1.759114e-07 | awk '{printf("%.3g\n", $1*1e2 ) }'
1.76e-05
Kusalananda
  • 333,661
  • 3
  • The question is whether all the awk flavors share the same limitations of printf in that answer. – r_31415 Jul 08 '22 at 00:35
  • @RobertSmith The main task in the question is to produce a number on the correct form. The user shows their attept at do so by using awk. This does not mean that the question is about awk, or that an answer need to use awk. In fact, it's not even tagged with awk, nor does it mention awk in the text. If the user comes back to clarify their question, it would possibly make sense to re-open the issue. If you have a question about this that is not answered by the duplicate, then feel free to post a separate question. – Kusalananda Jul 11 '22 at 19:56
  • @Kusalananda I just thought it was an interesting question and if clarification was needed, asking the user first whether awk is relevant to his question is a better policy than closing the question as a duplicate. I suspect awk is relevant here because of the very specific calculation. Otherwise, the user would have shown a much simpler example with bash's printf just to exemplify the concept. – r_31415 Jul 11 '22 at 20:14
  • @RobertSmith What usually happens is that the original user comes back saying "no, the duplicate does not answer my question because (specific reason)". This has not (yet) happened in this case. – Kusalananda Jul 11 '22 at 20:37
  • @Kusalananda Fair enough. – r_31415 Jul 11 '22 at 21:51

0 Answers0