Monday, November 08, 2010 at 12:05 AM.

system.verbs.builtins.string.percent

on percent (numerator, denominator, rodPlaces=3) {
	<<New verb: 4/8/00; 3:13:19 PM by DW
		<<As usual, this code was cropping up all over the place. Better to get it into the standard distribution.
	local (pct = "");
	if numerator > 0 {
		local (ratio = 100.0 * (double (numerator) / denominator));
		local (s = string (ratio));
		local (lod = string.nthfield (s, ".", 1));
		local (rod = string.nthfield (s, ".", 2));
		if sizeof (rod) > rodPlaces {
			rod = string.mid (rod, 1, rodPlaces)}
		else {
			if sizeof (rod) < rodPlaces {
				rod = rod + string.filledString (0, rodPlaces - sizeof (rod))}};
		pct = lod + "." + rod};
	return (pct)}
<<bundle //test code
	<<dialog.alert (percent (121, 10000, 5))



This listing is for code that runs in the OPML Editor environment. I created these listings because I wanted the search engines to index it, so that when I want to look up something in my codebase I don't have to use the much slower search functionality in my object database. Dave Winer.