blob: 9e0b662c13f50856a7fffaa84c0d1e403aba2d07 [file] [log] [blame]
<!DOCTYPE HTML>
<html lang="en">
<head>
<!-- Generated by javadoc (19) -->
<title>DecimalFunctions (Apache SIS 1.3 API)</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="description" content="declaration: package: org.apache.sis.math, class: DecimalFunctions">
<meta name="generator" content="javadoc/ClassWriterImpl">
<meta name="keywords" content="org.apache.sis.math.DecimalFunctions class">
<meta name="keywords" content="floatToDouble()">
<meta name="keywords" content="deltaForDoubleToDecimal()">
<meta name="keywords" content="fractionDigitsForDelta()">
<meta name="keywords" content="fractionDigitsForValue()">
<meta name="keywords" content="floorLog10()">
<meta name="keywords" content="equalsIgnoreMissingFractionDigits()">
<link rel="stylesheet" type="text/css" href="../../../../stylesheet.css" title="Style">
<link rel="stylesheet" type="text/css" href="../../../../sis.css" title="Style">
<link rel="stylesheet" type="text/css" href="../../../../script-dir/jquery-ui.min.css" title="Style">
<link rel="stylesheet" type="text/css" href="../../../../jquery-ui.overrides.css" title="Style">
<script type="text/javascript" src="../../../../script.js"></script>
<script type="text/javascript" src="../../../../script-dir/jquery-3.6.0.min.js"></script>
<script type="text/javascript" src="../../../../script-dir/jquery-ui.min.js"></script>
</head>
<body class="class-declaration-page">
<script type="text/javascript">var pathtoroot = "../../../../";
loadScripts(document, 'script');</script>
<noscript>
<div>JavaScript is disabled on your browser.</div>
</noscript>
<div class="flex-box">
<header role="banner" class="flex-header">
<nav role="navigation">
<!-- ========= START OF TOP NAVBAR ======= -->
<div class="top-nav" id="navbar-top"><button id="navbar-toggle-button" aria-controls="navbar-top" aria-expanded="false" aria-label="Toggle navigation links"><span class="nav-bar-toggle-icon">&nbsp;</span><span class="nav-bar-toggle-icon">&nbsp;</span><span class="nav-bar-toggle-icon">&nbsp;</span></button>
<div class="skip-nav"><a href="#skip-navbar-top" title="Skip navigation links">Skip navigation links</a></div>
<ul id="navbar-top-firstrow" class="nav-list" title="Navigation">
<li><a href="../../../../index.html">Overview</a></li>
<li><a href="package-summary.html">Package</a></li>
<li class="nav-bar-cell1-rev">Class</li>
<li><a href="class-use/DecimalFunctions.html">Use</a></li>
<li><a href="package-tree.html">Tree</a></li>
<li><a href="../../../../deprecated-list.html">Deprecated</a></li>
<li><a href="../../../../index-all.html">Index</a></li>
<li><a href="../../../../help-doc.html#class">Help</a></li>
</ul>
<ul class="sub-nav-list-small">
<li>
<p>Summary:</p>
<ul>
<li>Nested</li>
<li>Field</li>
<li>Constr</li>
<li><a href="#method-summary">Method</a></li>
</ul>
</li>
<li>
<p>Detail:</p>
<ul>
<li>Field</li>
<li>Constr</li>
<li><a href="#method-detail">Method</a></li>
</ul>
</li>
</ul>
</div>
<div class="sub-nav">
<div id="navbar-sub-list">
<ul class="sub-nav-list">
<li>Summary:&nbsp;</li>
<li>Nested&nbsp;|&nbsp;</li>
<li>Field&nbsp;|&nbsp;</li>
<li>Constr&nbsp;|&nbsp;</li>
<li><a href="#method-summary">Method</a></li>
</ul>
<ul class="sub-nav-list">
<li>Detail:&nbsp;</li>
<li>Field&nbsp;|&nbsp;</li>
<li>Constr&nbsp;|&nbsp;</li>
<li><a href="#method-detail">Method</a></li>
</ul>
</div>
<div class="nav-list-search"><a href="../../../../search.html">SEARCH</a>
<input type="text" id="search-input" disabled placeholder="Search">
<input type="reset" id="reset-button" disabled value="reset">
</div>
</div>
<!-- ========= END OF TOP NAVBAR ========= -->
<span class="skip-nav" id="skip-navbar-top"></span></nav>
</header>
<div class="flex-content">
<main role="main">
<!-- ======== START OF CLASS DATA ======== -->
<div class="header">
<div class="sub-title"><span class="package-label-in-type">Package</span>&nbsp;<a href="package-summary.html">org.apache.sis.math</a></div>
<h1 title="Class DecimalFunctions" class="title">Class DecimalFunctions</h1>
</div>
<div class="inheritance" title="Inheritance Tree"><a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/lang/Object.html" title="class or interface in java.lang" class="external-link">Object</a>
<div class="inheritance"><a href="../util/Static.html" title="class in org.apache.sis.util">Static</a>
<div class="inheritance">DecimalFunctions</div>
</div>
</div>
<section class="class-description" id="class-description">
<hr>
<div class="type-signature"><span class="modifiers">public final class </span><span class="element-name type-name-label">DecimalFunctions</span>
<span class="extends-implements">extends <a href="../util/Static.html" title="class in org.apache.sis.util">Static</a></span></div>
<div class="block">Functions working on <code>float</code> and <code>double</code> values while taking in account their representation in base 10.
Methods in this class may be helpful when used after parsing or before formatting a number in base 10:
<ul>
<li>Post-parsing methods <a href="#floatToDouble(float)"><code>float­To­Double(float)</code></a> and <a href="#deltaForDoubleToDecimal(double)"><code>delta­For­Double­To­Decimal(double)</code></a>:
<ul>
<li>for compensating error when the base 10 representation is considered <cite>definitive</cite>.</li>
</ul>
</li>
<li>Pre-formatting methods <a href="#fractionDigitsForValue(double)"><code>fraction­Digits­For­Value(double)</code></a> and
<a href="#fractionDigitsForDelta(double,boolean)"><code>fraction­Digits­For­Delta(double, boolean)</code></a>:
<ul>
<li>for formatting numbers using the exact amount of significant digits for a given precision.</li>
</ul>
</li>
</ul>
Methods in this class are usually <strong>not</strong> recommended for intermediate calculations,
since base 10 is not more "real" than base 2 for natural phenomenon.</div>
<dl class="notes">
<dt>Since:</dt>
<dd>0.4</dd>
<dt>See Also:</dt>
<dd>
<ul class="see-list">
<li><a href="MathFunctions.html#pow10(int)"><code>Math­Functions​.pow10(int)</code></a></li>
<li><a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/lang/Math.html#log10(double)" title="class or interface in java.lang" class="external-link"><code>Math​.log10(double)</code></a></li>
</ul>
</dd>
<p><font size="-1">Defined in the <code>sis-utility</code> module</font></p>
</dl>
</section>
<section class="summary">
<ul class="summary-list">
<!-- ========== METHOD SUMMARY =========== -->
<li>
<section class="method-summary" id="method-summary">
<h2>Method Summary</h2>
<div id="method-summary-table">
<div class="table-tabs" role="tablist" aria-orientation="horizontal"><button id="method-summary-table-tab0" role="tab" aria-selected="true" aria-controls="method-summary-table.tabpanel" tabindex="0" onkeydown="switchTab(event)" onclick="show('method-summary-table', 'method-summary-table', 3)" class="active-table-tab">All Methods</button><button id="method-summary-table-tab1" role="tab" aria-selected="false" aria-controls="method-summary-table.tabpanel" tabindex="-1" onkeydown="switchTab(event)" onclick="show('method-summary-table', 'method-summary-table-tab1', 3)" class="table-tab">Static Methods</button><button id="method-summary-table-tab4" role="tab" aria-selected="false" aria-controls="method-summary-table.tabpanel" tabindex="-1" onkeydown="switchTab(event)" onclick="show('method-summary-table', 'method-summary-table-tab4', 3)" class="table-tab">Concrete Methods</button></div>
<div id="method-summary-table.tabpanel" role="tabpanel">
<div class="summary-table three-column-summary" aria-labelledby="method-summary-table-tab0">
<div class="table-header col-first">Modifier and Type</div>
<div class="table-header col-second">Method</div>
<div class="table-header col-last">Description</div>
<div class="col-first even-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4"><code>static double</code></div>
<div class="col-second even-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4"><code><a href="#deltaForDoubleToDecimal(double)" class="member-name-link">delta­For­Double­To­Decimal</a><wbr>(double&nbsp;value)</code></div>
<div class="col-last even-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4">
<div class="block">Returns the difference between the given <code>double</code> value and the representation of that value in base 10.</div>
</div>
<div class="col-first odd-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4"><code>static boolean</code></div>
<div class="col-second odd-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4"><code><a href="#equalsIgnoreMissingFractionDigits(double,double)" class="member-name-link">equals­Ignore­Missing­Fraction­Digits</a><wbr>(double&nbsp;accurate,
double&nbsp;approximate)</code></div>
<div class="col-last odd-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4">
<div class="block">Returns <code>true</code> if the given numbers or equal or differ only by <code>accurate</code>
having more non-zero trailing decimal fraction digits than <code>approximate</code>.</div>
</div>
<div class="col-first even-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4"><code>static double</code></div>
<div class="col-second even-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4"><code><a href="#floatToDouble(float)" class="member-name-link">float­To­Double</a><wbr>(float&nbsp;value)</code></div>
<div class="col-last even-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4">
<div class="block">Converts the given <code>float</code> value to a <code>double</code> with the extra <em>decimal</em> fraction digits
set to zero.</div>
</div>
<div class="col-first odd-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4"><code>static int</code></div>
<div class="col-second odd-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4"><code><a href="#floorLog10(double)" class="member-name-link">floor­Log10</a><wbr>(double&nbsp;x)</code></div>
<div class="col-last odd-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4">
<div class="block">Computes <code>(int) floor(log10(x))</code>.</div>
</div>
<div class="col-first even-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4"><code>static int</code></div>
<div class="col-second even-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4"><code><a href="#fractionDigitsForDelta(double,boolean)" class="member-name-link">fraction­Digits­For­Delta</a><wbr>(double&nbsp;accuracy,
boolean&nbsp;strict)</code></div>
<div class="col-last even-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4">
<div class="block">Returns the number of fraction digits needed for formatting in base 10 numbers of the given
accuracy.</div>
</div>
<div class="col-first odd-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4"><code>static int</code></div>
<div class="col-second odd-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4"><code><a href="#fractionDigitsForValue(double)" class="member-name-link">fraction­Digits­For­Value</a><wbr>(double&nbsp;value)</code></div>
<div class="col-last odd-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4">
<div class="block">Returns the number of significant fraction digits when formatting the given number in base 10.</div>
</div>
<div class="col-first even-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4"><code>static int</code></div>
<div class="col-second even-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4"><code><a href="#fractionDigitsForValue(double,int)" class="member-name-link">fraction­Digits­For­Value</a><wbr>(double&nbsp;value,
int&nbsp;uncertain­Digits)</code></div>
<div class="col-last even-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4">
<div class="block">Returns the number of significant fraction digits, potentially minus trailing digits that may be rounding error.</div>
</div>
</div>
</div>
</div>
<div class="inherited-list">
<h3 id="methods-inherited-from-class-Object">Methods inherited from class&nbsp;<a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/lang/Object.html" title="class or interface in java.lang" class="external-link">Object</a></h3>
<code><a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/lang/Object.html#clone()" title="class or interface in java.lang" class="external-link">clone</a>, <a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/lang/Object.html#equals(java.lang.Object)" title="class or interface in java.lang" class="external-link">equals</a>, <a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/lang/Object.html#finalize()" title="class or interface in java.lang" class="external-link">finalize</a>, <a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/lang/Object.html#getClass()" title="class or interface in java.lang" class="external-link">get­Class</a>, <a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/lang/Object.html#hashCode()" title="class or interface in java.lang" class="external-link">hash­Code</a>, <a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/lang/Object.html#notify()" title="class or interface in java.lang" class="external-link">notify</a>, <a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/lang/Object.html#notifyAll()" title="class or interface in java.lang" class="external-link">notify­All</a>, <a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/lang/Object.html#toString()" title="class or interface in java.lang" class="external-link">to­String</a>, <a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/lang/Object.html#wait()" title="class or interface in java.lang" class="external-link">wait</a>, <a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/lang/Object.html#wait(long)" title="class or interface in java.lang" class="external-link">wait</a>, <a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/lang/Object.html#wait(long,int)" title="class or interface in java.lang" class="external-link">wait</a></code></div>
</section>
</li>
</ul>
</section>
<section class="details">
<ul class="details-list">
<!-- ============ METHOD DETAIL ========== -->
<li>
<section class="method-details" id="method-detail">
<h2>Method Details</h2>
<ul class="member-list">
<li>
<section class="detail" id="floatToDouble(float)">
<h3>floatToDouble</h3>
<div class="member-signature"><span class="modifiers">public static</span>&nbsp;<span class="return-type">double</span>&nbsp;<span class="element-name">floatToDouble</span><wbr><span class="parameters">(float&nbsp;value)</span></div>
<div class="block">Converts the given <code>float</code> value to a <code>double</code> with the extra <em>decimal</em> fraction digits
set to zero. This is different than the standard cast in the Java language, which set the extra <em>binary</em>
fraction digits to zero.
For example, <code>(double) 0.1f</code> gives 0.10000000149011612 while <code>float­To­Double(0.1f)</code> returns 0.1.
<div class="note"><b>Note:</b>
This method is <strong>not</strong> more accurate than the standard Java cast – it should be used only when
the base 10 representation of the given value may be of special interest. If the value come from a call to
<a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/lang/Float.html#parseFloat(java.lang.String)" title="class or interface in java.lang" class="external-link"><code>Float​.parse­Float(String)</code></a> (directly or indirectly), and if that call cannot be replaced by a call to
<a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/lang/Double.html#parseDouble(java.lang.String)" title="class or interface in java.lang" class="external-link"><code>Double​.parse­Double(String)</code></a> (for example because the original <code>String</code> is not available anymore),
then this method may be useful if one consider the <code>String</code> representation in base 10 as definitive.
But if the value come from an instrument measurement or a calculation, then there is probably no reason to use
this method because base 10 is not more "real" than base 2 or any other base for natural phenomenon.</div>
This method is equivalent to the following code, except that it is potentially faster since the
actual implementation avoid to format and parse the value:
<blockquote><pre><font color="green">return</font> Double.<b>parseDouble</b>(Float.<b>toString</b>(value));</pre></blockquote></div>
<dl class="notes">
<dt>Parameters:</dt>
<dd><code>value</code> - the <code>float</code> value to convert as a <code>double</code>.</dd>
<dt>Returns:</dt>
<dd>the given value as a <code>double</code> with the extra decimal fraction digits set to zero.</dd>
</dl>
</section>
</li>
<li>
<section class="detail" id="deltaForDoubleToDecimal(double)">
<h3>deltaForDoubleToDecimal</h3>
<div class="member-signature"><span class="modifiers">public static</span>&nbsp;<span class="return-type">double</span>&nbsp;<span class="element-name">deltaForDoubleToDecimal</span><wbr><span class="parameters">(double&nbsp;value)</span></div>
<div class="block">Returns the difference between the given <code>double</code> value and the representation of that value in base 10.
For any value in the method's domain of validity (defined below), this method is <em>approximately</em>
equivalent to the following code except that it is potentially faster since the actual implementation
avoids the creation of <a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/math/BigDecimal.html" title="class or interface in java.math" class="external-link"><code>Big­Decimal</code></a> objects:
<blockquote><pre>BigDecimal base2 = <font color="green">new</font> <b>BigDecimal</b>(value); <i><font color="gray">// Exact same value as stored in IEEE 754 format.</font></i>
BigDecimal base10 = BigDecimal.<b>valueOf</b>(value); <i><font color="gray">// Exact same value as shown by println(value).</font></i>
<font color="green">return</font> base10.<b>subtract</b>(base2).<b>doubleValue</b>();</pre></blockquote>
Computing <code>value + delta­For­Double­To­Decimal(value)</code> has no effect since the absolute value of the
returned delta is always smaller than <code><a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/lang/Math.html#ulp(double)" title="class or interface in java.lang" class="external-link">Math​.ulp</a>(value) / 2</code>.
To see an effect, a type with more precision than the <code>double</code> type is necessary.
<div class="note"><b>Use case:</b>
Many international standards define values in base 10. For example, the conversion factor from inches
to centimetres is defined as exactly 2.54 cm/inch. This is by an internationally accepted definition
since 1959, not an approximation. But the 2.54 value cannot be represented exactly in the IEEE 754
format – the error is approximately 3.6E-17 cm/inch. In the vast majority of cases such tiny error
can be ignored. But in situations where it is desirable to have an error estimation
(e.g. in non-linear equations where errors can grow exponentially), this method can be useful.
Other examples of values defined in base 10 are conversions from feet to metres and
map projection parameters defined by national mapping agencies.
</div>
<h4>Domain of validity</h4>
The current implementation cannot compute delta for <code>abs(value) &lt; 3E-8</code> approximately,
except for the 0 value which is supported. For any non-zero value closer to zero than the 3E-8
threshold, this method returns <code>Na­N</code> because of insufficient algorithm accuracy.
This limitation may change in any future SIS version if we find a better algorithm.</div>
<dl class="notes">
<dt>Parameters:</dt>
<dd><code>value</code> - the value for which to get the delta compared to its base 10 representation.</dd>
<dt>Returns:</dt>
<dd>the delta that would need to be added to the given <code>double</code> value for getting a result
closer to its base 10 representation, or <a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/lang/Double.html#NaN" title="class or interface in java.lang" class="external-link"><code>Na­N</code></a> if it cannot be computed.</dd>
</dl>
</section>
</li>
<li>
<section class="detail" id="fractionDigitsForDelta(double,boolean)">
<h3>fractionDigitsForDelta</h3>
<div class="member-signature"><span class="modifiers">public static</span>&nbsp;<span class="return-type">int</span>&nbsp;<span class="element-name">fractionDigitsForDelta</span><wbr><span class="parameters">(double&nbsp;accuracy,
boolean&nbsp;strict)</span></div>
<div class="block">Returns the number of fraction digits needed for formatting in base 10 numbers of the given
accuracy. If the <code>strict</code> argument is <code>true</code>, then for any given <code>accuracy</code>
this method returns a value <var>n</var> such as the difference between adjacent numbers
formatted in base 10 with <var>n</var> fraction digits will always be equal or smaller
than <code>accuracy</code>. Examples:
<ul>
<li><code>fraction­Digits­For­Delta(0.001, true)</code> returns 3.</li>
<li><code>fraction­Digits­For­Delta(0.009, true)</code> returns 3.</li>
<li><code>fraction­Digits­For­Delta(0.010, true)</code> returns 2.</li>
<li><code>fraction­Digits­For­Delta(0.099, true)</code> returns 3 (special case).</li>
</ul>
<p>Special cases:</p>
<ul>
<li>If <code>accuracy</code> is <a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/lang/Double.html#NaN" title="class or interface in java.lang" class="external-link"><code>Na­N</code></a> or infinity, then this method returns 0
since those values are not represented by decimal digits.</li>
<li>If <code>accuracy</code> is 0, then this method returns 324 since 10<sup>-324</sup> is the first power of 10
smaller than the minimal strictly positive <code>double</code> value (<a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/lang/Double.html#MIN_VALUE" title="class or interface in java.lang" class="external-link">4.9E-324</a>).
<div class="note"><b>Note:</b>
The above value can be understood in another way: if the first 324 fraction digits are zero,
then the IEEE <code>double</code> value is guaranteed to be rounded to exactly 0 no matter what the
next fraction digits are.</div></li>
<li>If <code>accuracy</code> is greater than 1, then this method returns
the number of "unnecessary" trailing zeros as a negative number.
<div class="note"><b>Example:</b> <code>fraction­Digits­For­Delta(100, …)</code> returns -2.</div></li>
<li>If the first non-zero digits of <code>accuracy</code> are equal or greater than 95
(e.g. 0.00099) and the <code>strict</code> argument is <code>true</code>, then this method
increases the number of needed fraction digits in order to prevent the rounded
number to be collapsed into the next integer value.
<div class="note"><b>Example:</b>
If <code>accuracy</code> is 0.95, then a return value of 1 is not sufficient since
the rounded value of 0.95 with 1 fraction digit would be 1.0. Such value would be a
violation of this method contract since the difference between 0 and that formatted
value would be greater than the accuracy. Note that this is not an artificial rule;
this is related to the fact that 0.9999… is mathematically strictly equals to 1.</div></li>
</ul>
Invoking this method is equivalent to computing <code>(int)
-<a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/lang/Math.html#floor(double)" title="class or interface in java.lang" class="external-link">floor</a>(<a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/lang/Math.html#log10(double)" title="class or interface in java.lang" class="external-link">log10</a>(accuracy))</code>
except for the 0, <code>Na­N</code>, infinities and <code>0.…95</code> special cases.</div>
<dl class="notes">
<dt>Parameters:</dt>
<dd><code>accuracy</code> - the desired accuracy of numbers to format in base 10.</dd>
<dd><code>strict</code> - <code>true</code> for checking the <code>0.…95</code> special case.
If <code>false</code>, then the difference between adjacent formatted numbers is not
guaranteed to be smaller than <code>accuracy</code> in every cases.</dd>
<dt>Returns:</dt>
<dd>number of fraction digits needed for formatting numbers with the given accuracy.
May be negative.</dd>
<dt>See Also:</dt>
<dd>
<ul class="see-list-long">
<li><a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/text/NumberFormat.html#setMaximumFractionDigits(int)" title="class or interface in java.text" class="external-link"><code>Number­Format​.set­Maximum­Fraction­Digits(int)</code></a></li>
</ul>
</dd>
</dl>
</section>
</li>
<li>
<section class="detail" id="fractionDigitsForValue(double)">
<h3>fractionDigitsForValue</h3>
<div class="member-signature"><span class="modifiers">public static</span>&nbsp;<span class="return-type">int</span>&nbsp;<span class="element-name">fractionDigitsForValue</span><wbr><span class="parameters">(double&nbsp;value)</span></div>
<div class="block">Returns the number of significant fraction digits when formatting the given number in base 10.
This method does <strong>not</strong> ignore trailing zeros.
For example, <code>fraction­Digits­For­Value(1.0)</code> returns 16,
because the <code>double</code> format can store <i>almost</i> 16 decimal digits after 1.
<div class="note"><b>Note:</b>
We said <cite>almost</cite> because the very last digit may be able to store only a subset
of the [0 … 9] digits.</div>
Invoking this method is equivalent to invoking <code><a href="#fractionDigitsForDelta(double,boolean)">fraction­Digits­For­Delta</a>(Math.<a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/lang/Math.html#ulp(double)" title="class or interface in java.lang" class="external-link">ulp</a>(value), false)</code>, except that it is
potentially faster.
<p>Special cases:</p>
<ul>
<li>If <code>value</code> is <a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/lang/Double.html#NaN" title="class or interface in java.lang" class="external-link"><code>Na­N</code></a> or infinity, then this method returns 0
since those values are not represented by decimal digits.</li>
<li>If <code>value</code> is 0, then this method returns 324 since
<code>Math​.ulp(0)</code> = <a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/lang/Double.html#MIN_VALUE" title="class or interface in java.lang" class="external-link">4.9E-324</a>.</li>
</ul>
<div class="note"><b>Example:</b>
This method is useful with <a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/text/NumberFormat.html" title="class or interface in java.text" class="external-link"><code>Number­Format</code></a> for formatting all significant digits of a
<code>double</code> value, padding with trailing zeros if necessary, but no more than necessary.</div></div>
<dl class="notes">
<dt>Parameters:</dt>
<dd><code>value</code> - the value for which to get the number of significant fraction digits.</dd>
<dt>Returns:</dt>
<dd>the number of significant fraction digits (may be negative), or 0 if <code>value</code> is NaN or infinity.</dd>
<dt>See Also:</dt>
<dd>
<ul class="see-list-long">
<li><a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/text/NumberFormat.html#setMinimumFractionDigits(int)" title="class or interface in java.text" class="external-link"><code>Number­Format​.set­Minimum­Fraction­Digits(int)</code></a></li>
</ul>
</dd>
</dl>
</section>
</li>
<li>
<section class="detail" id="fractionDigitsForValue(double,int)">
<h3>fractionDigitsForValue</h3>
<div class="member-signature"><span class="modifiers">public static</span>&nbsp;<span class="return-type">int</span>&nbsp;<span class="element-name">fractionDigitsForValue</span><wbr><span class="parameters">(double&nbsp;value,
int&nbsp;uncertainDigits)</span></div>
<div class="block">Returns the number of significant fraction digits, potentially minus trailing digits that may be rounding error.
First, this method gets the number of fraction digits as of <a href="#fractionDigitsForValue(double)"><code>fraction­Digits­For­Value(double)</code></a>. Then there
is a choice:
<ul>
<li>If after rounding the given <code>value</code> to an amount of fraction digits given by (<code>fraction­Digits</code>
- <code>uncertain­Digits</code>) the 4 last fraction digits before the rounded ones are zero, then this method
returns <code>fraction­Digits</code> - <code>uncertain­Digits</code>.</li>
<li>Otherwise this method returns <code>fraction­Digits</code>.</li>
</ul>
<div class="note"><b>Note:</b>
The threshold of 4 trailing fraction digits is arbitrary and may change in any future SIS version.</div>
<div class="note"><b>Examples:</b>
<ul>
<li><code>fraction­Digits­For­Value(179.12499999999824)</code> returns 14,
the amount of digits after the decimal separator.</li>
<li><code>fraction­Digits­For­Value(179.12499999999824, 3)</code> returns 11 because rounding the 3 last digits
(i.e. rounding after the 11<sup>th</sup> digit) results in 179.125000000000.
Since the 4 last fraction digits are zero, the condition for allowing that rounding is met.</li>
<li><code>fraction­Digits­For­Value(179.12499999999824, 2)</code> returns 14 because rounding the 2 last digits
(i.e. rounding after the 12<sup>th</sup> digit) results in 179.124999999998.
The condition for 4 trailing zero fraction digits is not met.</li>
<li><code>fraction­Digits­For­Value(179.12499997999999, 3)</code> returns 14 because rounding the 3 last digits
results in 179.12499997000. The condition for 4 trailing zero fraction digits is not met.</li>
</ul>
</div></div>
<dl class="notes">
<dt>Parameters:</dt>
<dd><code>value</code> - the value for which to get the number of significant fraction fraction digits minus rounding error.</dd>
<dd><code>uncertain­Digits</code> - number of trailing fraction digits which may be rounding error artefacts.</dd>
<dt>Returns:</dt>
<dd>suggested number of significant digits (may be negative), or 0 if <code>value</code> is NaN or infinity.</dd>
</dl>
</section>
</li>
<li>
<section class="detail" id="floorLog10(double)">
<h3>floorLog10</h3>
<div class="member-signature"><span class="modifiers">public static</span>&nbsp;<span class="return-type">int</span>&nbsp;<span class="element-name">floorLog10</span><wbr><span class="parameters">(double&nbsp;x)</span></div>
<div class="block">Computes <code>(int) floor(log10(x))</code>. For values greater than one, this is the number of digits - 1
in the decimal representation of the given number. For values smaller than one, this is the number of
fraction digits required for showing the first non-zero decimal digit.</div>
<dl class="notes">
<dt>Parameters:</dt>
<dd><code>x</code> - the value for which to compute the logarithm. Must be greater than zero.</dd>
<dt>Returns:</dt>
<dd>logarithm of the given value, rounded toward zero.</dd>
<dt>Throws:</dt>
<dd><code><a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/lang/ArithmeticException.html" title="class or interface in java.lang" class="external-link">Arithmetic­Exception</a></code> - if the given value is zero, negative, infinity or NaN.</dd>
<dt>Since:</dt>
<dd>1.0</dd>
<dt>See Also:</dt>
<dd>
<ul class="see-list">
<li><a href="MathFunctions.html#pow10(int)"><code>Math­Functions​.pow10(int)</code></a></li>
</ul>
</dd>
</dl>
</section>
</li>
<li>
<section class="detail" id="equalsIgnoreMissingFractionDigits(double,double)">
<h3>equalsIgnoreMissingFractionDigits</h3>
<div class="member-signature"><span class="modifiers">public static</span>&nbsp;<span class="return-type">boolean</span>&nbsp;<span class="element-name">equalsIgnoreMissingFractionDigits</span><wbr><span class="parameters">(double&nbsp;accurate,
double&nbsp;approximate)</span></div>
<div class="block">Returns <code>true</code> if the given numbers or equal or differ only by <code>accurate</code>
having more non-zero trailing decimal fraction digits than <code>approximate</code>.
<table class="sis">
<caption>Examples</caption>
<tr><th>Accurate</th> <th>Approximate</th> <th>Result</th> <th>Comment</th></tr>
<tr><td>0.123456</td> <td>0.123</td> <td>true</td> <td>Differ in digits not specified by <code>approximate</code>.</td></tr>
<tr><td>0.123456</td> <td>0.123000</td> <td>true</td> <td>This method cannot distinguish missing digits from trailing zeros.</td></tr>
<tr><td>0.123456</td> <td>0.123001</td> <td>false</td> <td>No missing digits, and some of them differ.</td></tr>
<tr><td>0.123</td> <td>0.123456</td> <td>false</td> <td><code>approximate</code> and <code>accurate</code> cannot be interchanged.</td></tr>
</table>
<div class="note"><b>Use case:</b>
this method is useful when <code>approximate</code> is a number parsed by <a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/lang/Double.html#parseDouble(java.lang.String)" title="class or interface in java.lang" class="external-link"><code>Double​.parse­Double(String)</code></a>
and the data producer may have rounded too many fraction digits when formatting the numbers.
In some cases we can suspect what the real value may be and want to ensure that a replacement
would not contradict the provided value. This happen for example in Well Known Text format,
where the following element is sometimes written with the conversion factor rounded:
<blockquote><pre>AngleUnit["degree", 0.017453292519943295] // Expected
AngleUnit["degree", 0.01745329252] // Given by some providers</pre></blockquote>
</div></div>
<dl class="notes">
<dt>Parameters:</dt>
<dd><code>accurate</code> - the most accurate number.</dd>
<dd><code>approximate</code> - the number which may have missing decimal fraction digits.</dd>
<dt>Returns:</dt>
<dd>whether the two number are equal, ignoring missing decimal fraction digits in <code>approximate</code>.</dd>
<dt>Since:</dt>
<dd>1.0</dd>
</dl>
</section>
</li>
</ul>
</section>
</li>
</ul>
</section>
<!-- ========= END OF CLASS DATA ========= -->
</main>
<footer role="contentinfo">
<hr>
<p class="legal-copy"><small>Copyright &#169; 2010&#x2013;2022 <a href="https://www.apache.org/">The Apache Software Foundation</a>. All rights reserved.</small></p>
</footer>
</div>
</div>
</body>
</html>