Click here to Skip to main content
15,895,142 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
"Write a Java program named <<yourname>>Assign5 that generate PI to a user defined decimal places (No rounding).
Make sure you use Math.PI (PI is estimated as: 3.141592653589793)
If the user select to choose 5 decimal places the output should be: 3.14159 not 3.14160
Also
If the user select to choose 4 decimal places the output should be: 3.1415 not 3.1416"
I have no idea how to do this!

What I have tried:

I don't know where to start. We never learned this in class so it makes no sense to me.
Posted
Updated 12-Nov-17 10:01am

1 solution

Quote:
I don't know where to start. We never learned this in class so it makes no sense to me.

It actually makes sense.
A possible algorithm is described by the following example:
Suppose you're asked to provide two decimal digits.
Starting from
pi = 3.141592653589793

take just the integer part, namely 3
then multiply the remaining number by 10, obtaining
1.41592653589793

take the integer part, namely 1
make another step
4.1592653589793
obtaining 4.
The result is
3.14
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900