File: average.md

package info (click to toggle)
bnd 5.0.1-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye
  • size: 44,092 kB
  • sloc: java: 249,039; xml: 90,727; sh: 655; perl: 153; makefile: 95; python: 47; javascript: 9
file content (25 lines) | stat: -rw-r--r-- 600 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
---
layout: default
class: Macro
title: average (';' LIST )*
summary: The average of a list, if no members exception is thrown
---

	static String	_average	= "${average;<list>[;<list>...]}";

	public String _average(String args[]) throws Exception {
		verifyCommand(args, _sum, null, 2, Integer.MAX_VALUE);

		List<String> list = toList(args, 1, args.length);
		if (list.isEmpty())
			throw new IllegalArgumentException("No members in list to calculate average");

		double d = 0;

		for (String s : list) {
			double v = Double.parseDouble(s);
			d += v;
		}
		return toString(d / list.size());
	}