1

Hi i am new to java can anyone help me to convert this formula to java code?

=ROUNDUP(POWER(4*B18/PI(),1/3)*100,0)

So far, I have this code:

(((4*variable)/3.142)*0.34)*100;

sorry for asking basic question

5
  • 3
    Sure we can do it. But first, what have you tried? Commented Nov 21, 2013 at 15:18
  • 2
    Don't be sorry for asking a basic question. But be sorry for not attempting. Commented Nov 21, 2013 at 15:19
  • (((4*variable)/3.142)*0.34)*100; Commented Nov 21, 2013 at 15:19
  • I believe Java has a MATH.Pi constant. so 'Pi' is taken care of. please do a little more code-efforts Commented Nov 21, 2013 at 15:20
  • I would highly recommend downloading (or at least bookmarking) the java api. The class java.lang.Math has all the methods you need. Commented Nov 21, 2013 at 15:30

2 Answers 2

6

In its raw (and ugly) form, it should be something like this:

static double yourFormula(double b18) {
    return Math.ceil(Math.pow(4.0 * b18 / Math.PI, 1.0/3) * 100.0);
}

EDIT: As noted by @Teepeemm, Math#cbrt already calculates the cube root of a number. So the formula should be

static double yourFormula(double b18) {
    return Math.ceil(Math.cbrt(4.0 * b18 / Math.PI) * 100.0);
}
Sign up to request clarification or add additional context in comments.

12 Comments

I think you want Math.ceil() instead of Math.round().
Not to be picky, for clarity 1.0/3.0
@Emmentaler 1.0/3 is just fine :).
Strange that the answer lacks output for excel issue. And everyone upvotes. See the post title.
@Ravinder what do you mean?
|
0
double multiplies =8 * 4;
System.out.println(Math.floor(Math.pow( multiplies/ Math.PI, 1.0/3)*100.0));

double multiplies =8 * 4;
System.out.println(Math.ceil(Math.pow( multiplies/ Math.PI, 1.0/3)*100.0));

double multiplies =8 * 4;
System.out.println(Math.round(Math.pow( multiplies/ Math.PI, 1.0/3)*100.0));

depending on your usage you can use this three methods

1 Comment

thanks suganthan you ceil suggestion worked exactly in my java app code

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.