Re: Suggestion for Eu 2.5
- Posted by "Euman" <euman at bellsouth.net> Jan 13, 2004
- 431 views
Hi, Here are some routines (not written by me), they come in handy though. The Authors names have been retained. -- Thanks Don Phillips, Adds appropriate commas to large numbers ------------ function AddCommas( atom above ) atom below sequence answer integer sign atom after below = 0 sign = (above >= 0) * 2 - 1 above *= sign after = above - floor(above) above = floor(above) answer = {} if after != 0 then answer = sprint(after) answer = answer[2..length(answer)] end if while above != 0 do below = remainder( above, 1000 ) above = floor( above / 1000 ) if above then answer = sprintf(",%03d",{below}) & answer end if end while answer = sprint(below) & answer if sign = -1 then answer = '-' & answer end if return( answer ) end function -- Thanks Pete Lomax, strip comma's string -------------------------------- function RemCommas(integer id) integer k, lt text=getText(id) lt=length(text) while 1 do k=find(',',text) if k=0 then exit end if if k>lt then exit end if text[k..lt-1]=text[k+1..lt] lt-=1 end while return text[1..lt] end function Euman ----- Original Message ----- From: "Kurt Faasse" <darkside at frontiernet.net> > More options for printf would be useful. Large numbers could be > separated by commas at the appropriate places by putting a comma after > the percent sign, e.g. "%,d" to print 12345678 as 12,345,678. Right now > I'm working on an astronomical program that involves huge distances, and > comma separated numbers would be easier on the eye. I will have to > write a routine that prints the numbers with commas as a separate > function. If printf had this built in, the speed price would be > negligible.