number-manipulation

rounding in base 10

折月煮酒 提交于 2019-12-08 06:51:00
问题 I have a function to round a number given to the function to the nearest whole pence. <script type='text/javascript'> Math.roundNumber = function(a,b){ if(!isNaN(parseInt(a))){ c = Math.pow(10,b); return (Math.round(a*c)/c); } return false; } </script> however it has come to my attention that the said number inputted into the function must only be rounded up to the nearest one pence however it must be rounded to two decimal places. E.G. 15.236562213541684 would = 15.24 9846.65456169846 would

Return the nth digit of a number [closed]

元气小坏坏 提交于 2019-11-28 12:53:54
public class Return { public static void main(String[] args) { int answer = digit(9635, 1); print("The answer is " + answer); } static void print(String karen) { System.out.println (karen); } static int digit(int a, int b) { int digit = a; return digit; } } Create a program that uses a function called digit which returns the value of the nth digit from the right of an integer argument. The value of n should be a second argument. For Example: digit(9635, 1) returns 5 and digit(9635, 3) returns 6 . Without spoon-feeding you the code: The nth digit is (the remainder of dividing by 10 n ) divided

Return the nth digit of a number [closed]

梦想与她 提交于 2019-11-26 21:57:04
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 6 years ago . public class Return { public static void main(String[] args) { int answer = digit(9635, 1); print("The answer is " + answer); } static void print(String karen) { System.out.println (karen); } static int digit(int a, int b) { int digit = a; return digit; } } Create a program that uses a function called digit