# Formatted Division Coderbyte Solution

0

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.

Formatted Division Coderbyte Solution In Java

import java.text.DecimalFormat;
import java.util.Scanner;

public class FormattedDivision {
String FormattedDivision(double num1,
double num2) {

double div = num1 / num2;
DecimalFormat decFormat = new
DecimalFormat("#,###,##0.0000");

return decFormat.format(div);

}

public static void main (String[] args) {
// keep this function call here
Scanner s = new Scanner(System.in);
FormattedDivision c = new
FormattedDivision();
System.out.print(c.FormattedDivision(2, 3));
}
}

Formatted Division Coderbyte Solution In Python

def FormattedDivision(num1,num2):
temp = "%.4f" %(float(num1)/num2)
return "{:,}".format(float(temp))
print FormattedDivision(raw_input())

Formatted Division Coderbyte Solution In JavaScript

function FormattedDivision(num1, num2){
var quotient = num1 / num2;
var fixed = quotient.toFixed(4);
var parts = fixed.toString().split(".");
parts[0] = parts[0].replace
(/\B(?=(\d{3})+(?!\d))/g, ",");
return parts.join(".");
}