Name

nfc()

Description

Utility function for formatting numbers into strings and placing appropriate commas to mark units of 1000. There are four versions: one for formatting ints, one for formatting an array of ints, one for formatting floats, and one for formatting an array of floats.

The value for the right parameter should always be a positive integer.

For a non-US locale, this will insert periods instead of commas, or whatever is appropriate for that region.

Examples

  • int i = 500000; 
    String si = nfc(i);
    println(si);  // Prints "500,000"
    float f = 42525.34343; 
    String fi = nfc(f, 2);
    println(fi);  // Prints "42,525.34"
    
    
  • int[] i = { 500000, 4000 }; 
    String[] si = nfc(i);
    println(si);  // Prints "500,000 4,000"
    float[] f = { 42525.34343, 3.14159 }; 
    String[] fi = nfc(f, 2);
    println(fi);  // Prints "42,525.34 3.14"
    
    

Syntax

  • nfc(nums)
  • nfc(num)
  • nfc(nums, right)
  • nfc(num, right)

Parameters

  • nums(int[], float[])the numbers to format
  • num(int, float)the number to format
  • right(int)number of digits to the right of the decimal point

Return

  • String[]