TopCoder problem "PiCalculator" used in SRM 246 (Division I Level One)



Problem Statement

    

The problem statement contains the unicode symbols.

You are developing a new software calculator. A very important feature is the auto-placing of the ? value by one click. The only problem is that you don't know the required precision. That's why you decided to write a program that can return ? with any reasonable precision.

You are given an int precision. You should return the ? value with exactly precision digits after the decimal point. The last digit(s) should be rounded according to the standard rounding rules (less than five round down, more than or equal to five round up).

 

Definition

    
Class:PiCalculator
Method:calculate
Parameters:int
Returns:String
Method signature:String calculate(int precision)
(be sure your method is public)
    
 

Notes

-? equals 3.141592653589793238462643383279...
 

Constraints

-precision will be between 1 and 25, inclusive.
 

Examples

0)
    
2
Returns: "3.14"
1)
    
4
Returns: "3.1416"
The value should be rounded.
2)
    
12
Returns: "3.141592653590"
Be careful with rounding.

Problem url:

http://www.topcoder.com/stat?c=problem_statement&pm=4470

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=7221&pm=4470

Writer:

Andrew_Lazarev

Testers:

PabloGilberto , lbackstrom , brett1479

Problem categories:

String Manipulation