Convert from scientific notation to integer

  • Follow


Hi all, I have a process which outputs numbers in scientific format
like this: 2.2242013611E+03.
I would like to convert it to an integer. I tried to use awk without
much success.
Any pointers?
Any dc wizards out there? It'll be cool if this can be done in dc, but
any shell solution is good enough.
Thanks,
Sashi
0
Reply smalladi (87) 12/3/2009 2:49:13 PM

Sashi wrote:

> Hi all, I have a process which outputs numbers in scientific format
> like this: 2.2242013611E+03.
> I would like to convert it to an integer. I tried to use awk without
> much success.

$ echo '2.2242013611E+03' | awk '{printf "%.4f\n", $0}'
2224.2014

adapt to the format you want.

1
Reply pk 12/3/2009 3:09:00 PM


On Dec 3, 10:09=A0am, pk <p...@pk.invalid> wrote:
> Sashi wrote:
> > Hi all, I have a process which outputs numbers in scientific format
> > like this: 2.2242013611E+03.
> > I would like to convert it to an integer. I tried to use awk without
> > much success.
>
> $ echo '2.2242013611E+03' | awk '{printf "%.4f\n", $0}'
> 2224.2014
>
> adapt to the format you want.

Thank you!
Sashi
1
Reply Sashi 12/3/2009 3:22:32 PM

On 12/03/09 23:09, pk <pk@pk.invalid> wrote:

> Sashi wrote:
>
>> Hi all, I have a process which outputs numbers in scientific format
>> like this: 2.2242013611E+03.
>> I would like to convert it to an integer. I tried to use awk without
>> much success.
>
> $ echo '2.2242013611E+03' | awk '{printf "%.4f\n", $0}'
> 2224.2014
>
> adapt to the format you want.
>

You can avoid awk, use printf(1):

% printf "%.4f\n" "3.1415926E+03"
3141.5926

-- 
Live like a child, think like the god.
 
0
Reply WANG 12/6/2009 8:24:36 AM

WANG Cong wrote:

> You can avoid awk, use printf(1):
> 
> % printf "%.4f\n" "3.1415926E+03"
> 3141.5926

Ah, true, thanks. Sometimes the most obvious things are not seen. I guess I 
was biased by his sayng "awk" so I just thought of that. 

0
Reply pk 12/6/2009 12:13:29 PM

4 Replies
2215 Views

(page loaded in 0.258 seconds)

Similiar Articles:













7/19/2012 7:15:14 PM


Reply: