Problem: program outputs numbers in scientific notation
my problem is that my program outputs the population in scientific notation instead of round the number to the nearest one. ex: it should say 30787949.57 instead of 3.078794957 E7
// Calculates the poulation of Mexico City from 1995 to 2018.
// displays the year and population
class PopulationCalculator {
static double r2(double x) {
//this method rounds a double value to two decimal places.
double z=((double)(Math.round(x*100)))/100;
return z;
} //end method r2
public static void main(String args[]) {
double population=15600000.0;
double rate=0.03;
System.out.println("Mexico City Population, rate="+r2(rate));
System.out.println("Year Population");
for (int year=1995; year<=2018;year++) {
System.out.println(year+ " "+r2(population));
population+=rate*population;
}//end for loop
System.out.println("The population of Mexico City reaches 30 million on 02/13/17 at 5:38:34am");
}//end main
}//end PopulationCalculator
{code/]
Or upgrade to JDK 5.0 and user the new java.util.Formatter capability.
You control the rounding and get localization of the fomatted string at
no extra charge. A quick example:
class A {
public static void main(String[] args) {
double d = 30787949.57d;
System.out.println(java.lang.String.format("%,17.2f", d));
}Example output for three different locales:
$ javac -g A.java
$ LC_ALL=fr_FR java A
30 787 949,57
$ LC_ALL=en_NZ java A
30,787,949.57
$ LC_ALL=it_IT java A
30.787.949,57For more information, refer to:
http://java.sun.com/j2se/1.5.0/docs/relnotes/features.html#formatter
Or upgrade to JDK 5.0 and user the new java.util.Formatter capability.
You control the rounding and get localization of the fomatted string at
no extra charge. A quick example:
class A {
public static void main(String[] args) {
double d = 30787949.57d;
System.out.println(java.lang.String.format("%,17.2f", d));
}Example output for three different locales:
$ javac -g A.java
$ LC_ALL=fr_FR java A
30 787 949,57
$ LC_ALL=en_NZ java A
30,787,949.57
$ LC_ALL=it_IT java A
30.787.949,57For more information, refer to:
http://java.sun.com/j2se/1.5.0/docs/relnotes/features.html#formatter
Similar Messages
-
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 -
Probem with numbers in scientific notation
Hi, I Have a problem and I don�t know how to be solved this.
I have a array of array ( String a[ ][ ] ) with numbers, but this numbers are like 2.48e+08
I need to copy the values of the String a [ ] [ ] into other Double b [ ] [ ] . So I do:
String a [ ][ ] = new String [10][2];
// now I have filled up "a"
Double [ ][ ] b = new Double[10][2];
for(int i =0;i<10;i++)
for(int j=0;j<2;j++)
b[i][j] = new Double( a[i][j]);
.......But my problem is that:
tha values like 2.48e+08 have been transformed to 2.48E8 and I need that they are like the original ones (like 2.48e+08).
it is possible to maintain the original format in this numbers?
Thanks very muchNo. A double value does not have a format, it is just a number. However if you want to display those double values in some particular format, then DecimalFormat is the class you use to do that.
-
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 -
DecimalFormat issues/Scientific notation
I have 2 issues with formatting numbers with scientific notation via the DecimalFormat class
ISSUE 1: Disregard of the number of MAXIMUM FRACTOINAL DIGITS
in the code:
NumberFormat nf = NumberFormat.getInstance();
DecimalFormat df = (DecimalFormat)nf;
df.applyPattern("#00.#E0");
System.out.println( df.format(12345678));
it printed: 12.35E6
Why does it violate my request for one significant digit beyond the decimal
point?. (Note, this problem
only seems to occur when when the sum of MAX integer and Max fractional
digits in my pattern is 4)
ISSUE 2:
Number of significant digits displayed:- I really just need a sanity check on this one
The 1.4.2 API for DecimalFormat states
? The number of significant digits in the mantissa is the sum of the minimum integer and
maximum fraction digits, and is unaffected by the maximum integer digits. For example,
12345 formatted with "##0.##E0" is "12.3E3". To show all digits, set the significant digits
count to zero. The number of significant digits does not affect parsing.
I tried this ? it displays 123.45E3, or 5 significant digits? Looks like the number of significant digits
is MAX integer + MAX fractional digits in a pattern. Am I correct (and the API not correct)?
thanks
carolThanks. I'm assuming you're responding to issue #1. I did try it, and it worked, as expected. I never seem to have an issue when all symbols
preceding the decimal are 0. My issue, I suppose, is the inconsistency of how the formatting
works, when it comes to the number of fractional digit positions. Most of the times it 'behaves' and
only prints out the number of digits you ask, but sometimes it does not.
I've tested quite a few combinations. I'm attaching the code (in case you need help sleeping tonight).
The only 'pattern' I've noticed is that this issue only occurs when the total number of digits specified
in the pattern (before and after decimal) is 4. (exception ... if all digits specified before the decimal
are 0s, this never occurs)
I know a simple solution ... make sure I never have
a total of 4 #s and 0s in my pattern. But again, my question is why ... and/or ... does this type of
inconsistency crop up elsewhere.
import java.util.*;
import java.text.*;
public class x {
public static void main(String [] args) {
NumberFormat nf = NumberFormat.getInstance();
DecimalFormat df = (DecimalFormat)nf;
// these 3 work like I'd expect: 3 digits to the left, one to the right w/ rounding
// signif digits = max int digits + max fractional digits
df.applyPattern("000.#E0");
System.out.println( df.format(12345678)); // 123.5E5
df.applyPattern("00.#E0");
System.out.println( df.format(12345678)); // 12.3E6
df.applyPattern("0.#E0");
System.out.println( df.format(12345678)); // 1.2E7
// signif digits = TOTAL int digits + max fractional digits
System.out.println("X");
df.applyPattern("###.#E0"); // how did it decide to place decimal where it did?
System.out.println( df.format(12345678)); // 12.35E6 // why did it violate my "1 max fractional digit"
// request? I would have expected 123.5E5
df.applyPattern("##.#E0");
System.out.println( df.format(12345678)); // 12.3E6
df.applyPattern("#.#E0");
System.out.println( df.format(12345678)); // 1.2E7
//signif digits - TOTAL int digits + max fractional didgits
System.out.println("");
System.out.println("XXXXXXXX");
df.applyPattern("#000.#E0");
System.out.println( df.format(12345678)); // 1234.6E4
df.applyPattern("#00.#E0");
System.out.println( df.format(12345678)); // 12.35E6 // how did it decide to place decimal where it did?
// why did it violate my "1 max fractional digit"
// request? I would have expected 123.5E5
df.applyPattern("#0.#E0");
System.out.println( df.format(12345678)); // 12.3E6
// significant digtis = TOTAL int digits + max fractional digits
System.out.println("");
df.applyPattern("###0.#E0");
System.out.println( df.format(12345678)); // 1234.6E4
df.applyPattern("##0.#E0"); // how did it decide to place decimal where it did?
System.out.println( df.format(12345678)); // 12.35E6 // why did it violate my "1 max fractional digit"
// request? I would have expected 123.5E5
System.out.println( df.format(12345678)); // 12.35E6
df.applyPattern("##.#E0");
System.out.println( df.format(12345678)); // 12.3E6
//API example from DecimaFormat RE Scientific Notation.. api says this will print 12.3E3
df.applyPattern("###.##E0");
System.out.println( df.format(12345)); //12.345E3 //violates max fractiona digit request
//NOTE DOCS ARE WRONG ... the number of significant digits is = to max integer digits (number of # and 0 prior
// to decimal point) PLUS max number of digits after the decimal point... NOT Min. Integer digits + Max fractional digits
// suggested pattern
df.applyPattern("000000.##E0");
System.out.println( df.format(12345678)); //123456.78 -
Select Query resulting in Scientific Notation
Hello all,
I am running a Select query through a batch file that extracts data from an Oracle database. Several of the fields that I am extracting from contain numbers that are up to 38 digits long. When I extract the data, it converts the numbers into scientific notation and it is important for me to have the entire field. Is there something I can change to my query that will pull the data in its entire form? This is what I'm running now:
select * FROM ML.APPT where APPTDATE >= to_date('01/1/2010','mm/dd/yyyy'
I apologize in advance if this has been answered already.
Thanks!>
When the extractor finishes, it returns the data into a flat file.
don't quite understand the TO_CHAR function. Does this function mean I need to say something like this: select "TO_CHAR('column name', 99999999999999999999999999999999999999" FROM ML.APPT where APPTDATE >= to_date('01/1/2010','mm/dd/yyyy')
>
Yes- if the tool you use to extract the data (your 'extractor') is converting the numeric data to a string then it is responsible for creating the string in the proper format. If the number is an integer that can have as many digits as you have '9's in your sample format string then that is what you need to do.
Here is how sql*plus (Oracle's tool) will display the data using default settings
SQL> select 12345678901234567890123456789012345678 no_format,
2 to_char(12345678901234567890123456789012345678, '99999999999999999999999999
999999999999') with_format
3 from dual;
NO_FORMAT WITH_FORMAT
1.2346E+37 12345678901234567890123456789012345678
SQL>
----- TOAD will display something similiar but the default uses more decimal digits in the scientific notation data
NO_FORMAT,WITH_FORMAT
1.23456789012346E37, 12345678901234567890123456789012345678You can either format the numeric data in the query using TO_CHAR or the 'extractor' can do it when it converts the data to a string. -
Long number in CSV file appearing in scientific notation by default
Hi,
How can I stop a long number in a CSV file that is opened in excel from appearing in scientific notation by default?
eg.
"hello","778002405501 ", "yes"
becomes:
hello | 7.78002E+11 | yes
I have tried wrapping the data in quotes in the csv but to no avail.
Thanks in advance,
AlistairYou can change the extension from ".csv" to ".xls" and use table to form the data and use
style=”mso-number-format:\@;”
Please read the sample code below in Classic ASP:
You can also read in my blog http://sarbashish.wordpress.com/2012/11/30/export-to-excel-how-to-prevent-long-numbers-from-scientific-notation/
<%
Response.Clear
Response.CacheControl = “no-cache”
Response.AddHeader “Pragma”, “no-cache”
Response.Expires = -1
Response.ContentType = “application/vnd.ms-excel”
Dim FileName
FileName = “TestDB Lookup-” & month(now)&”-”&day(now)&”-”&year(now)&”.xls”
Response.AddHeader “Content-Disposition”, “inline;filename=” & FileName
%>
<html xmlns:o=”urn:schemas-microsoft-com:office:office” xmlns:x=”urn:schemas-microsoft-com:office:excel” xmlns=”http://www.w3.org/TR/REC-html40″;>
<head>
<meta http-equiv=Content-Type content=”text/html; charset=UTF-8″>
<!–[if gte mso 9]>
<xml>
<x:ExcelWorkbook>
<x:ExcelWorksheet>
<x:WorksheetOptions>
<x:DisplayGridlines/>
</x:WorksheetOptions>
</x:ExcelWorksheet>
</x:ExcelWorksheets>
</x:ExcelWorkbook>
</xml>
<![endif]–>
</head>
<body>
<table border=”0″>
<tr>
<td>ID</td>
<td>Name</td>
</tr>
<tr>
<td style=”mso-number-format:\@;”>01234567890123456567678788989909000030</td>
<td>Sarbashish B</td>
</tr>
</table>
</body>
</html>
Sarbashish Bhattacharjee http://sarbashish.wordpress.com -
How can I get Numbers 3.2 to recognise 1e-5 as scientific notation?
I just changed from Numbers '09 (2.3) to Number 3.2 on Mavericks (OS X 10.9.3) and the new version doesn't seem to recognise "e" or "E" as scientific notation. When I set the cell format to scientific and type "0.0015", Numbers returns "1.5×10^-03". I would however prefer to obtain "1.5e-3". And vice versa: if, after setting the cell format to scientific, I type "1.5e-3", it automatically formats the cell as text and I can't get it to recognise it as scientific notation. With "E" instead of "e", the problem is exactly the same. Does anyone know how I can change this setting? I already tried to search for an answer to my question, but couldn't find anything...
if, after setting the cell format to scientific, I type "1.5e-3", it automatically formats the cell as text and I can't get it to recognise it as scientific notation.
I can't duplicate the problem here, either when the cells are formatted as Automatic or as Scientific:
When you type 1.5e-3 are you making sure not to enter a space after the e? (When I type a space the cell automatically formats as Text.)
SG -
Since numbers 3.1 rendering problem in output
Since I upgraded to Numbers 3.1 all printed output is no more crispy, it looks like a rendering problem. My Number documents consist of normal text elements and tables, sometimes some charts. Scaling on printout is not activated. On the Mac display the problem does not exist, everything seems to be fine, also in large zoom factors. But printing the document produces some kind of unrendered, pixely output, comparable to a screenshot, by far not that crisp as in Numbers 3.0.1. Other applications such as Pages, Word, Excel are not affected, printouts are fine.
What I did so far:
- uninstall and reinstall numbers
- changing, reinstalling the printer driver (HP Color LaserJet 2025 Series), I use the Postscript driver
- converting the Number documents to Numbers '09 and opening them again
- playing and testing with numerous zoom factors
- changing fonts in the Numbers document
... all without any success.
What helped me was:
- Installing Numbers 3.0.1 again using TimeMachine, installed it parallel to Numbers 3.1
- In Numbers 3.1 exporting the Numbers document to Numbers '09
- Opening that document in Numbers 3.0.1
- Printing the document in Numbers 3.0.1 --> Output ist fine and perfect.
It seems to be a rendering problem, only in Numbers 3.0.1. The problem appears in all existing and new Numbers documents on Numbers 3.1.
Here is my infrastructure:
MacBook Air Mid 2013, OS X Mavericks 10.9.1
Numbers 3.1 (1769)
HP Color LaserJet CP2025dn using PostScript
Many thanks for your help!
speckchPerhaps you can see the problem in this version. This is a PRINTING problem. You cannot see it on screen in the pdf.
This is a single Numbers document, printed directly from Numbers (3.1). The font is identical in both lines. The box color is identical (black) and the width of the line is identical (0.5 pt). It was printed on an HP Color LaserJet CP2025.
The upper text is jagged. It may look fine on your screen, but it's not.
This is very obvious if you look at the larger image that is linked to the image above. (Remember, a computer screen is only 72 dpi and this image is optimized for that. Printed text is much higher resolution. So, to get an accurate view on your screen of how jagged the text is when printed, you need to look at it magnified. Right-click on the image above to open the image in a new tab, and you should get the full size.)
Also, the because the upper image is lower resolution (jaggies), the narrow line cannot print accurately. Thus, it appears blueish. When you look at the full-size image, you can see how jagged the line is and the mix of dots (red and blue, predominantly) that was output by the printer. In contrast, the lower text box is smooth and black.
I don't know where the problem lies, but I have not experienced anything like this on any other program I currently use. It's a postscript printer, and I suspect that something's gone wrong in the postscript output associated with tables and the printer is printing the screen view, not the higher resolution printer data. But that's just a guess. And as far as I know, it's not something anyone other than Apple can fix.
And, of course, since you can't see this problem on screen in the pdf, no matter how much you "zoom" in, you won't know if your files will print badly until you test it. Or, worse, your client does.
Bummer. -
Preventing automatic scientific notation conversion for excel output?
I have a column in a report that contains a mixture of numbers and letters and hyphens. If the only letter is E, then I get scientific notation instead of the actual text when I run the report for excel output and open it in excel.
For example:
185701E-02 becomes 1.86E+03
4962E6 becomes 4.96E+09
Any ideas how to fix or work around this in the template, data definition, or excel config?
Thanks,
KevinI tried pre-pending an apostrophe in the SQL and in the rtf template to indicate to excel that it is a text field, but this just resulted (not surprisingly) in '185701E-02 instead of 185701E-02
-
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. -
Powershell / Scientific Notation Woes / Formatting Output to Live Excel Sheet
I have a WMI query in a script that dumps machine information to a live excel sheet.
I find when I query the model # of the machine using (this line of code from the script):
$Sheet.Cells.Item($count,4) = (Get-WmiObject win32_computersystem -ComputerName $computer).Model
The output almost always changes into Scientific Notation, because this is a typical model number : "3500-E52"
Is there a way to modify the formatting of the:
$Sheet.Cells.Item($count,4)
so that Excel uses "text" formatting for that cell? I know you can change the fonts etc... but have not been lucky in finding a powershell > excel reference
that explains how to change a cell or column's formatting beyond the basics.
I have seen recommendations to others to dump the results queries to a CSV first, and then import into Excel (which would allow a manual change of that column's format). I'm just
hoping to bypass the extra "hands on" and format more directly to a sheet in Excel.
If .csv is the best way to go, I'll muddle through it and change the code.
Any help is greatly appreciated.
Ben$sheet.Cells(1,1).NumberFormat
= "@"
¯\_(ツ)_/¯ -
Prevent large numbers from becoming scientific notation on CSV import
Hi, I'm importing contacts in a .CSV file into iWork Numbers and it takes a 12-digit phone number from a guy in the UK and turns it into scientific notation. So something like 447729803988 becomes 4.4772E+11 which obviously loses some important digits. Is there a way to force Numbers to treat all fields as text on import so it doesn't drop this critical data? thanks
Seanscrollin,
Your digits are all there. Just format those cells to either Text or Number. Leading zeros do tend to get lost unless you pre-format to text. You can force the cell format to text on the fly by prefixing your input with a single-quote.
Regards,
Jerry -
Hi,
I'm working with a small program where at one point a number, in scientific notation will need to be formated into a string containing plane numbers.
I use the code below, and it works in up to large numbers where the formatting doesen't do aything at all.
String InputValue = "7,584995286E7";
NumberFormat format = NumberFormat.getNumberInstance();
Number number = format.parse(InputValue);
String OutputValue = number.toString();
System.out.println(OutputValue);The example above gives the result input back as output value: 7.584995286E7
With the value 7,584995286E6 the result is: 7584995.286 just as I want it to work.
What can I do to solve this?
All help is appreciated.
Thanks
/H�kanHi ,
Below is the code posted by you.
String InputValue = "7,584995286E7";
NumberFormat format = NumberFormat.getNumberInstance();
Number number = format.parse(InputValue);
String OutputValue = number.toString();
System.out.println(OutputValue);Add these two methods, and you will get the code working as you needed.
format .setMaximumFractionDigits(3)
format .setMinimumFractionDigits(3);
Best regards
Aneesh A.V -
Preventing automatic scientific notation conversion for excel o/p of bi pub
I have a column in a query that contains a mixture of numbers and letters and hyphens. If the only letter is E, then I get scientific notation instead of the actual text,when I run the report for excel output and open it in excel.
For example:
185701E-02 becomes 1.86E+03 in the excel output of the report
4962E6 becomes 4.96E+09
will be really grateful if anyone can helpSee this thread:
Re: Long account Numbers displayed in exponential form in excel using XML Pub
Regards,
Dave
Maybe you are looking for
-
How can we know the feature we planned to add has crossed apple's border line
Currently, we have an application, which is able to measure your heart rate by using camera to capture human face. we plan to add in 1 new feature into our app Let the application runs in stealth mode background, acquire camera resource and perform c
-
Hi, How to extract the content from IDOCs.e.g mautiple idocs are comming.we need to retrive the company ID from all the IDOC.So Please tell me how to extract. Regards, Suchitra
-
I lost my GigaWorks S750 power cord
I recently moved and apparently lost the power cord for the subwoofer in the process. I have looked and looked and can't find where to purchase a replacement. Sorry if I'm uneducated, but where can I find a replacement power cord specifically for thi
-
Hi guys, I bought a new 2TB Samsung USB3 disk for 139SGD and I worried I might not have set it up correctly at EXT4 drive for backups: x220:~$ sudo fdisk -l /dev/sdc Disk /dev/sdc: 1.8 TiB, 2000398934016 bytes, 3907029168 sectors Units: sectors of 1
-
In the browser Chrome, after going to a website starting with https://, it gave me the below message: Mixed Content: The page at 'https://...' was loaded over HTTPS, but requested an insecure resource 'http://...'. This request has been blocked; the