Double and scientific notation
Hi,
I am using a Double to store data but when i output it the value
is printed in scientific notation example, 2.3333E5..I want to print it as decimal without the 'E' notation, is there a way to format it or set the precision in Java???
Many Thanks
You can have a look at NumberFormat and also search this forum because it's a frequently asked question.
Similar Messages
-
Double in Scientific Notation after Marshal
Hi,
I have an element defined as an xsd:double. If I try and place a value say 100 into the element and then I marshal it I get an output of <Quantity>100.0</Quantity>... That is fine....
However, if I put a value in of say 1000000000, I get an output of <Quantity>1.0E9</Quantity> when I marshal.
Can I turn a setting on (or off) so the output does not get converted into scientific notation?
-jI also verified the XML standard and you are right that the values are legal xsd:double values. What made this a problem for me is that the XSLT functions that use XPATH number() to process these values failed because XPATH specifies that a number is:
Number ::= Digits ( '.' Digits?)? | '.' Digits
which does not handle the exponents at all. So the XML documents produced could not be handled by XSLT processors.
For fun, I redefined my schema definition to replace xsd:double with:
<xs:simpleType name="simpleDouble">
<xs:restriction base="xs:double">
<xs:pattern value="(-)?[0-9]*(.[0-9]+)?" />
</xs:restriction>
</xs:simpleType>
which is essentially a non-exponent based double. JAXB rendered the document, but then the validator complained that the output did not match the pattern. So JAXB does not use this pattern as a method of determining output, only as a method of validation.
This is why I replaced the DoubleType class for my solution. The alternative of using the jaxb:globalBindings is probably a cleaner approach. I think I'll switch my implementation. Thanks for the pointer!
-Allan -
Decimal Format and Scientific Notation
I am trying to print numbers in scientific notation using the Decimal Format class. What follows is a simple test program I wrote to find the bug. So far, I have not found a solution.
import java.text.*;
public class formatted {
public static void main (String Arguments[]) {
DecimalFormat form = new DecimalFormat("0.###E0");
double numb = 123456.789;
System.out.println("Nuber is: " +
form.format(numb));
The output of this program is... Nuber is: 123456E
The output is the same if numb is an int, float, or double. If I format the number as "#####.0" or "#####.00" the output is correct. I think that I am following the rules for formatting a number in scientific notation as the process is outlined in the documentation (provided below).
***** From Decimal Format under Scientific Notation ***
Numbers in scientific notation are expressed as the product of a mantissa and a power of ten, for
example, 1234 can be expressed as 1.234 x 10^3. The mantissa is often in the range 1.0 <= x < 10.0,
but it need not be. DecimalFormat can be instructed to format and parse scientific notation only via a
pattern; there is currently no factory method that creates a scientific notation format. In a pattern,
the exponent character immediately followed by one or more digit characters indicates scientific
notation. Example: "0.###E0" formats the number 1234 as "1.234E3".
Anyone understand how the short program is incorrectly written?
MarcThe problem is
format = "0.###E0"
input number = 123456.789
output = 123456E (not scientific notation!)
This is not scientific notation at all. There is no decimal point given and no value in the exponent.
I understand entirely that by adding more #'es will provide more precision. The bug I have is the output is not printed in the scientific format; other formats work.
MArc -
External table.How to load numbers (decimal and scientific notation format)
Hi all, I need to load inside an external table records that contain 7 fields. The last field is called AMOUNT and it's represented in some records with the decimal format, in others records with the scientific notation format as, for example, below:
CY001_STATU;2009;Jan;11220020GR;'03900;CYZ900;-9,99999999839929e-03
CY001_STATU;2009;Jan;11200100;'60800;CYZ900;41380,77
The External table's script is the following:
CREATE TABLE HYP_DATA
COUNTRY VARCHAR2(50 BYTE),
YEAR VARCHAR2(20 BYTE),
PERIOD VARCHAR2(20 BYTE),
ACCOUNT VARCHAR2(50 BYTE),
DEPT VARCHAR2(20 BYTE),
ACTIVITY_LOC VARCHAR2(20 BYTE),
AMOUNT VARCHAR2(50 BYTE)
ORGANIZATION EXTERNAL
( TYPE ORACLE_LOADER
DEFAULT DIRECTORY HYP_DATA_DIR
ACCESS PARAMETERS
( RECORDS DELIMITED BY NEWLINE
BADFILE 'HYP_BAD_DIR':'HYP_LOAD.bad'
DISCARDFILE 'HYP_DISCARD_DIR':'HYP_LOAD.dsc'
LOGFILE 'HYP_LOG_DIR':'HYP_LOAD.log'
SKIP 0
FIELDS TERMINATED BY ";"
MISSING FIELD VALUES ARE NULL
REJECT ROWS WITH ALL NULL FIELDS
"COUNTRY" Char,
"YEAR" Char,
"PERIOD" Char,
"ACCOUNT" Char,
"DEPT" Char,
"ACTIVITY_LOC" Char,
"AMOUNT" Char
LOCATION (HYP_DATA_DIR:'Total.txt')
REJECT LIMIT UNLIMITED
NOPARALLEL
NOMONITORING;
If, for the field AMOUNT I use the datatype VARCHAR (as above), the table is loaded but I have some records rejected, and all these records contain the last field AMOUNT with the scientific notation as:
CY001_STATU;2009;Jan;11220020GR;'03900;CYZ900;-9,99999999839929e-03
CY001_STATU;2009;Feb;11220020GR;'03900;CYZ900;-9,99999999839929e-03
CY001_STATU;2009;Mar;11220020GR;'03900;CYZ900;-9,99999999839929e-03
CY001_STATU;2009;Dec;11220020GR;'03900;CYZ900;-9,99999999839929e-03
All the others records with a decimal AMOUNT are loaded correctly.
So, my problem is that I NEED to load all the records (with the decimal and the scientific notation format) together (without records rejected), but I don't know which datatype I have to use for the AMOUNT field....
Anybody has any idea ???
Any help would be appreciated
Thanks in advance
Alex@OP,
What version of Oracle are you using?
Just cut'n'paste of you script and example woked FINE for me.
however my quation is... An external table will LOAD all data or none at all. How are you validating/concluding that...
I have some records rejected, and all these records contain the last field AMOUNT with the scientific notation
select * from v$version where rownum <2;
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi
select * from mydata;
CY001_STATU 2009 Jan 11220020GR '03900 CYZ900 -9,99999999839929e-03
CY001_STATU 2009 Feb 11220020GR '03900 CYZ900 -9,99999999839929e-03
CY001_STATU 2009 Jan 11220020GR '03900 CYZ900 -9,99999999839929e-03
CY001_STATU 2009 Jan 11200100 '60800 CYZ900 41380,77
CY001_STATU 2009 Mar 11220020GR '03900 CYZ900 -9,99999999839929e-03
CY001_STATU 2009 Dec 11220020GR '03900 CYZ900 -9,99999999839929e-03
CY001_STATU 2009 Jan 11220020GR '03900 CYZ900 -9,99999999839929e-03
CY001_STATU 2009 Jan 11200100 '60800 CYZ900 41380,77MYDATA table script is...
drop table mydata;
CREATE TABLE mydata
COUNTRY VARCHAR2(50 BYTE),
YEAR VARCHAR2(20 BYTE),
PERIOD VARCHAR2(20 BYTE),
ACCOUNT VARCHAR2(50 BYTE),
DEPT VARCHAR2(20 BYTE),
ACTIVITY_LOC VARCHAR2(20 BYTE),
AMOUNT VARCHAR2(50 BYTE)
ORGANIZATION EXTERNAL
( TYPE ORACLE_LOADER
DEFAULT DIRECTORY IN_DIR
ACCESS PARAMETERS
( RECORDS DELIMITED BY NEWLINE
BADFILE 'IN_DIR':'HYP_LOAD.bad'
DISCARDFILE 'IN_DIR':'HYP_LOAD.dsc'
LOGFILE 'IN_DIR':'HYP_LOAD.log'
SKIP 0
FIELDS TERMINATED BY ";"
MISSING FIELD VALUES ARE NULL
REJECT ROWS WITH ALL NULL FIELDS
"COUNTRY" Char,
"YEAR" Char,
"PERIOD" Char,
"ACCOUNT" Char,
"DEPT" Char,
"ACTIVITY_LOC" Char,
"AMOUNT" Char
LOCATION (IN_DIR:'total.txt')
REJECT LIMIT UNLIMITED
NOPARALLEL
NOMONITORING;vr,
Sudhakar B. -
To_number and scientific notation
Hi
I am trying to convert a number in scientific notation stored in a character ffield to a number.
I use this statement, but gets a ORA-01722 error.
What is wrong ?
select to_number('1.1111111111111112E-6','9.9EEEE')
from dual
PrebenHi guys, I'm following this forum in order to reuse what you wrote, but I still have a problem with the scientific notation format...
From SQL Plus If I run this query:
select b.CONTRACT_NUMBER,b.id as cont_id from OKC_K_HEADERS_B b--, okc_k_lines_b v
where b.contract_number = 'NR19Mini'
I retrieve the following row:
CONTRACT_NUMBER CONT_ID
NR19Mini 1.4733E+38where the CONT_ID datatype is NUMBER.
Now I want to specify a condition using the CONT_ID field (for another use in the future), but if I use the following syntax
select b.CONTRACT_NUMBER,b.id as cont_id from OKC_K_HEADERS_B b
where b.contract_number = 'NR19Mini'
and b.id = to_number('1.4733E+38','9.99999EEEE');
I don't retrieve any rows (no rows selected)
How can I modify the format number in order to see my row, and for example use it inside a join with another fied of the same type ?
Thanks in advance
Alex -
Numeric value and scientific notation
Hi,
with Oracle 8 or 10, the query (via TOAD or my app : Delphi + BDE)
SELECT 0.0008 FROM DUAL returns 0.0008,
but the query
SELECT 0.00008 FROM DUAL returns 8E-5.
Is there a way to avoid this display in scientific notation, except changing all my queries ? Or to push the limit for this display one digit later ?
Maybe with an Oracle parameter ?
Thanks for your help !duplicate for thread
numeric value and scientific notation -
Numberformatter and scientific notation
Hello all. I'm having an issue with Numberformatter that I could use some assistance with. It looks like this:
<mx:NumberFormatter id="numberFormatter"
precision="6"
rounding="up"
useThousandsSeparator="false"
useNegativeSign="true"/>
I'm applying it to a Number object that was created from a deserialized java BigDecimal. In most cases, this is successful. So, 0.000024603877571 becomes 0.000025 and so on.
However, in some cases, my Number is in scientific notation like "0E-15". In this case, the NumberFormatter formats the number as -15.000000. Not helpful. Any ideas on what is going on and how I might could work around it?Thanks for the quick response, Michael. I was about to simply change the sending of the numbers as a string when I decided to try one more thing. If I use toFixed() on my number first (before the NumberFormatter.format() function) it seems to fix the issue. So, for example, in my label function for a column of a datagrid that has Numbers that sometimes appear in scientific notation, I do something like this:
public function myNumberLabelFunction(item:Object, column:DataGridColumn):String
var myNumber:Number = item.number;
var myNumberString:String = myNumber.toFixed(20);
return numberFormatter.format(myNumberString);
That (toFixed) appears to not mess up the regular numbers as well as the ones that have E notation. I don't know if anyone has any thoughts on the workaround. It seems to work find since my formatter is ultimately rounding to a precison of 6. -
Calculator and Scientific Notation
My Calculator App seems to randomly switch back to scientific notation instead of displaying results in regular x.xx format.
I tried deleting the com.apple.calculator.plist file and then relaunching Calculator but that didn't work.
Any other suggestions on how to get the calculator app back to displaying results in normal (non-scientific notation) mode?
thanksThen, I'm at a loss. Mine only shows scientific notation when the value exceeds whatever's set as the number's max range. You might want to peruse Calculator's help files.
-
Calculator.app Version 4.5.3 (99.2) and Scientific Notation
I want to enter a number with scientific notation.
2.71e1 doesn't return 27.1, but rather 0.999...
It seems that Calculator.app is dividing by e.
This is not a common operation.
2.71E1 gives 27.1great! But ...
2.71E-1 does not return 0.271 neither does
2.71E(-1)
I have yet to figure out how to use negative exponents in Scientific notation.
This seems to be a bug in Calculator.app Version 4.5.3 (99.2)All my spaces were deleted.
Take two.
My input ======= Calculator
2 ============ 2
2. ============ 2.
2.7 =========== 2.7
2.7E ========== 2.7 E 0
2.7E- ========== 2.7 (and the small - subscript indicating a negative number)
2.7E-1 ========= 1 (and the small - subscript indicating a negative number)
Now hitting enter === 1.7 (it appears to have subtracted 1 from 2.7)
Do our version of Calculator match?
Thanks for being interested. -
Float Data Value and Scientific Notation
Hello All,
SQL Server converts some of the float value into scientific notation for example 0.00001 will be stored as
1E-05.
Is there any simple method\formula\threshold to precisely tell when some particular value will be converted to scientific notation?
Also I think oracle store same value above i.e. 0.00001 as it is with float data type but not the case with SQL Server. Any reason for the same?
Thanks in Advance.
-MalkeshThanks Erland.
I got your point that internal storage as you mentioned will be 53 bit and 11 bit exponent of 2. However my question remains the same that is there any method\threshold from which we can say that after this numeric value stored data will be represented in
scientific notation or any rule of thumb? For example
drop
table #t
CREATE
TABLE #T (T1
FLOAT)
INSERT
INTO #T (T1)
SELECT 0.000001
INSERT
INTO #T (T1)
SELECT 0.00001
INSERT
INTO #T (T1)
SELECT 0.0001
INSERT
INTO #T (T1)
SELECT 0.001
INSERT
INTO #T (T1)
SELECT 0.01
INSERT
INTO #T (T1)
SELECT 0.1
INSERT
INTO #T (T1)
SELECT 1.
INSERT
INTO #T (T1)
SELECT 1.0
INSERT
INTO #T (T1)
SELECT 1.01
INSERT
INTO #T (T1)
SELECT 1.001
INSERT
INTO #T (T1)
SELECT 1.0001
INSERT
INTO #T (T1)
SELECT 1.00001
INSERT
INTO #T (T1)
SELECT 1.000001
INSERT
INTO #T (T1)
SELECT 1.0000001
INSERT
INTO #T (T1)
SELECT 1.00000001
INSERT
INTO #T (T1)
SELECT 1.000000001
INSERT
INTO #T (T1)
SELECT 1.0000000001
INSERT
INTO #T (T1)
SELECT 1.00000000001
INSERT
INTO #T (T1)
SELECT 1.000000000001
INSERT
INTO #T (T1)
SELECT 1.1
INSERT
INTO #T (T1)
SELECT 10.1
INSERT
INTO #T (T1)
SELECT 100.1
INSERT
INTO #T (T1)
SELECT 1000.1
INSERT
INTO #T (T1)
SELECT 10000.1
INSERT
INTO #T (T1)
SELECT 100000.1
INSERT
INTO #T (T1)
SELECT 1000000.1
INSERT
INTO #T (T1)
SELECT 10000000.1
INSERT
INTO #T (T1)
SELECT 100000000.1
INSERT
INTO #T (T1)
SELECT 1000000000.1
INSERT
INTO #T (T1)
SELECT 10000000000.1
INSERT
INTO #T (T1)
SELECT 100000000000.1
INSERT
INTO #T (T1)
SELECT 1000000000000.1
SELECT T1
FROM #T
Here you can see value < 0.0001 i.e. 0.00001 and 0.000001 both are in scientific notation. So which rule or formula drives this behavior that is what my question is. Sorry I am somewhat poor in mathematics fundamentals So if you can make it simple.
Thanks Again. -
Converting from a double to scientific notation
does anyone know how I can convert a double value to scientific notation?
java.text.DecimalFormat can do that.
-
Iphone and Scientific Notation
I have a problem with my new iphone's calculator. When I go to the scientific calculator it does not go into scientific notation mode. I could have sworn that when I was at the apple store a month ago that the same calculator on the floor that I checked out went into scientific notation when I rotated it.
the tech on the help line did not even know what scientific notation was---am I missing something here? or does my iphone have a glitch? ( I have version 2.02 on it.)It still does when the full width of digits is exceeded, but in landscape mode that's a lot of digits!
-
Formatting Doubles with Scientific Notation Depending on Exponent Size
Hi there. I was just wondering if there was a better way to do the following:
DecimalFormat fmt;
if (v>=1.0E9 || v<=-1.0E9 || (v>-1.0E-8 && v<1.0E-8 && v!=0.0 && v!=-0.0))
fmt = new DecimalFormat("0.########E0");
else fmt = new DecimalFormat("0.########");
return fmt.format(v);I'm not an expert on DecimalFormat, so I may have missed something, but the only improvement I can see is to remove the v!=-0.0 check. 0.0==-0.0, so it's unnecessary.
-
Double.parseDouble(String) - problems when string is in scientific notation
Hello guys,
I'm doing some numerical calculations and I wonder whether it is possible for Double.parseDouble(String) to parse string in the scientific notation i.e. 1.0824234234E-10. Is it the notation itself causing the exception : NumberFormatException or the number is just too big/small and double can't hold it ?
If it's just the notation how can I fix it ?
Regardsi'm not quite sure whether double odoes not allow it.
perhaps consider the api Double.valueOf() and the testing code provided; reproduced below:To avoid calling this method on a invalid string and having a NumberFormatException be thrown, the regular expression below can be used to screen the input string:
final String Digits = "(\\p{Digit}+)";
final String HexDigits = "(\\p{XDigit}+)";
// an exponent is 'e' or 'E' followed by an optionally
// signed decimal integer.
final String Exp = "[eE][+-]?"+Digits;
final String fpRegex =
("[\\x00-\\x20]*"+ // Optional leading "whitespace"
"[+-]?(" + // Optional sign character
"NaN|" + // "NaN" string
"Infinity|" + // "Infinity" string
// A decimal floating-point string representing a finite positive
// number without a leading sign has at most five basic pieces:
// Digits . Digits ExponentPart FloatTypeSuffix
// Since this method allows integer-only strings as input
// in addition to strings of floating-point literals, the
// two sub-patterns below are simplifications of the grammar
// productions from the Java Language Specification, 2nd
// edition, section 3.10.2.
// Digits ._opt Digits_opt ExponentPart_opt FloatTypeSuffix_opt
"((("+Digits+"(\\.)?("+Digits+"?)("+Exp+")?)|"+
// . Digits ExponentPart_opt FloatTypeSuffix_opt
"(\\.("+Digits+")("+Exp+")?)|"+
// Hexadecimal strings
"((" +
// 0[xX] HexDigits ._opt BinaryExponent FloatTypeSuffix_opt
"(0[xX]" + HexDigits + "(\\.)?)|" +
// 0[xX] HexDigits_opt . HexDigits BinaryExponent FloatTypeSuffix_opt
"(0[xX]" + HexDigits + "?(\\.)" + HexDigits + ")" +
")[pP][+-]?" + Digits + "))" +
"[fFdD]?))" +
"[\\x00-\\x20]*");// Optional trailing "whitespace"
if (Pattern.matches(fpRegex, myString))
Double.valueOf(myString); // Will not throw NumberFormatException
else {
// Perform suitable alternative action
http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Double.html -
Create an NSString for number in scientific notation from double?
Hi
Given a double, I want to create a string in scientific notation.
e.g for a double with a value of 123.456, I want the NSString to be "1.23456e+2" for entering in to a UITextField.
I've looked through the docs but can't find a formatter. (There is mention of "%a" being scientific format, but it produces hex output.)
Thanks for any clues.
SteveHere, you should find what you are looking for:
http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/Strings/Ar ticles/FormatStrings.html#//apple_ref/doc/uid/20000943
http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/Strings/Ar ticles/FormatStrings.html#//apple_ref/doc/uid/20000943
http://developer.apple.com/mac/library/documentation/Cocoa/Reference/Foundation/ Classes/NSStringClass/Reference/NSString.html#//appleref/occ/clm/NSString/stringWithFormat:
Maybe you are looking for
-
Hi! Does anybody know why I get error 56 with Telnet Read function even connection is workin fine and I can receive messages trough Telnet? I have tryed to use Line read and normal mode. With normal mode i have use bytes to read values, which are sam
-
Send SRM Purchase order Cancellation request to Vendor using SAP PI
Hi gurus, We have to build an interface to send Purchase order cancellation request to vendor once the PO is deleted in SRM using PI. Could some one please send me out a document to set up this interface. Thanks in advance for your help. Regards, Cat
-
Hi Guru's I want to implement EHP3 reporting: 1)Does is working well if anybody has implemented same. 2) what is solution for DSO , between 0FIAR_C30 and 0FI_AR_30 and others. Efforts would be definatly appreciated. thanks Micky
-
I need to update LR4 so I can import Nikon Df images. When I try to update a message says there are no new updates. Please help?
-
Error Opening Template in Excel 2000
Hello, I am using BI Publisher version 10.1.3.3.1 with Excel 2000 SP-3. When I try to view a report in Excel 2000 and if the report contains a chart or a graph or even an image, I get the error message "Microsoft Excel has encountered a problem and n