Skip to content

Instantly share code, notes, and snippets.

@jtara1
Created September 24, 2016 22:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jtara1/7d2aa09ef6fc9a7db824bf59ef1dffad to your computer and use it in GitHub Desktop.
Save jtara1/7d2aa09ef6fc9a7db824bf59ef1dffad to your computer and use it in GitHub Desktop.
public class MyClass {
public static void main(String[] args) {
BigDecimal[] mathArray2 = mathStuff2();
System.out.println("mathStuff2 func return:");
for (BigDecimal num: mathArray2) {
System.out.println(num);
}
public static BigDecimal[] mathStuff2() {
double area, theta, x, y;
double r = 1.0; // radius of unit circle
area = Math.PI * Math.pow(r, 2.0);
theta = (1.0 / 2) * Math.PI; // 1/2 PI radians
x = r * Math.cos(theta);
y = r * Math.sin(theta);
// convert double variables to BigDecimal inside of new BigDecimal array
BigDecimal[] ret = new BigDecimal[]{
new BigDecimal(area),
new BigDecimal(theta),
new BigDecimal(x),
new BigDecimal(y)
};
for (BigDecimal val: ret) {
val.setScale(7, RoundingMode.FLOOR);
}
return ret;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment