<%bte.doc super="item.bte" %> <%bte.tpl name=pageTitle%>Significant Figures<%/bte.tpl%> <%bte.tpl name=description%>Handles parsing, rounding, and displaying numbers for scientific applications.<%/bte.tpl%> <%bte.tpl name=keywords%>significant figures java library, significant digits java library, scientific rounding java library, java significant figures<%/bte.tpl%> <%bte.tpl name=content%>

Example

// Numbers to multiply
String[] args = {"1.0", "2.0"}; 
SignificantFigures number;
int sigs = Integer.MAX_VALUE;
double result = 1D;
for (int i=0; i<args.length; i++){
    // For each number, figure out significant figures
    // and multiply the numbers
    number = new SignificantFigures(args[i]);
    sigs = Math.min(sigs, number.getNumberSignificantFigures());
    result *= number.doubleValue();
}
// format and display the result
number = new SignificantFigures(result);
number.setNumberSignificantFigures(sigs);
System.out.println(number);
Figure significant figures for multiplication of numbers.

A Java number class for figuring out how many significant figures each of the numbers in a calculation has and displaying the result appropriately.

[Download /w Source | Version History | Browse Source | Documentation]


Example

// Numbers to add
String[] args = {"1.0", "2.0"}; 
SignificantFigures number;
int lsd = Integer.MIN_VALUE;
int msd = Integer.MIN_VALUE;
double result = 0D;
for (int i=0; i<args.length; i++){
    // for each number figure most and least
    // significant digit then add the number.
    number = new SignificantFigures(args[i]);
    lsd = Math.max(lsd, number.getLSD());
    msd = Math.max(msd, number.getMSD());
    result += number.doubleValue();
}
// format and display the result
number = new SignificantFigures(result);
number.setLMSD(lsd, msd);
System.out.println(number);
Figure significant figures for addition of numbers.

See also: JavaScript routines and an HTML interface for significant figures calculations.


<%/bte.tpl%> <%/bte.doc%>