Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

foo=${(z)${(s:.:)SECONDS}} ; echo ${foo[1]}.${(r:2:)foo[2]}



from the man page...

For example, `typeset -F SECONDS' causes the value to be reported as a floating point number. The precision is six decimal places, although not all places may be useful.

but i see something like this...
	% echo $SECONDS
	25912.5868740000

with ten decimal places.

i want that number to be reported only to hundredths of a second (two decimal places). i could just say that there are 10 decimal places and i want to get rid of eight:
	print "${SECONDS/%????????/}"
	25867.46

but that would break if the number of digits after the decimal point changes. which leads me to:
	% foo=${(z)${(s:.:)SECONDS}} ; echo ${foo[1]}.${(r:2:)foo[2]}
	25969.87

which works fine, but i'm wondering if there's a more graceful way to do that without an intermediate variable (foo, in this case).

any ideas....?


--
        ...atom

 ________________________
 http://atom.smasher.org/
 762A 3B98 A3C3 96C9 C6B7 582A B88D 52E4 D9F5 7808
 -------------------------------------------------

	"But that one 16 ounce cut of prime rib is equal to a
	 thousand gallons of fresh water, a few acres of grass,
	 a few fish, a quarter acre of corn etc. What's the
	 point of taking a shorter shower to conserve water as
	 Greenpeace is preaching if you can sit down and
	 consume a 1000 gallons of water at a single meal? And
	 that single cut of meat would have cost as much in
	 vegetable resources equivalent to what could be fed to
	 an entire African village for a week."
		-- Capt Paul Watson, A Very Inconvenient Truth




Messages sorted by: Reverse Date, Date, Thread, Author