(Coderbyte) Formatted Division - Solução

Have the function FormattedDivision(num1,num2) take both parameters being passed, divide num1 by num2, and return the result as a string with properly formatted commas and 4 significant digits after the decimal place. For example: if num1 is 123456789 and num2 is 10000 the output should be "12,345.6789". The output must contain a number in the one's place even if it is a zero.

import java.util.*;
import java.io.*;
import java.text.*;

class Function { 
  String FormattedDivision(int num1, int num2) {
    DecimalFormat df = new DecimalFormat("#,##0.0000");

    return df.format((double)num1/num2);
   
  }
 
  public static void main (String[] args) { 
    // keep this function call here    
    Scanner  s = new Scanner(System.in);
    Function c = new Function();
    System.out.print(c.FormattedDivision(s.nextLine()));
  }  
 
}

Comments

Popular posts from this blog

(Coderbyte) Powers of Two - Solução

(Coderbyte) Dash Insert II - Solução

(CoderByte) Number Search - Solução