0

I want to round pi number to an integer and then use it in drawLine command with the following code:

double pi = Math.PI
g.drawLine(0, 0, 0, n * Math.sin(5 * pi));

but as you know the drawLine command doesn't take double input and it gives error. so can someone tell me how can i solve the problem?

either round the number to integer or if there is an equivalent command to drawLine for double input?

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
  • 1
    Welcome to Stack Overflow! Please review our [SO Question Checklist](http://meta.stackoverflow.com/questions/260648/stack-overflow-question-checklist) to help you to ask a good question, and thus get a good answer. – Joe C Nov 04 '18 at 10:48
  • Hi @Hadi Asghari, if you want to get some information about equivalent of drawLine() method you will need to tell others where it came from, because it's hard to guess what kind of library/technology you are using, is it Swing, JavaFX, AWT? Also I'd suggest to check Java documentation for casting and intValue() method of the Double class. This should help you. – Kamil Nov 04 '18 at 10:51

1 Answers1

0

Just cast it to an int:

g.drawLine(0, 0, 0, (int) (n * Math.sin(5 * pi)));

See this post for more on casting.

MWB
  • 1,830
  • 1
  • 17
  • 38