Converting Scientific notation values into numeric one while reading csv file which is serialized automaticallyConvert numbers with exponential notation from string to double or decimalCSV file Read in PythonIn C#, how can I create a TextReader object from a string (without writing to disk)Python: Convert string (in scientific notation) to floatHow can I convert scientific notation to text from CSV file using PHPconvert scientific notation number into normal number by php?How To Parse a Scientific Notation Value Back To Original Value When Reading CSV In C#Convert Scientific notation to decimal in csvHow to import long number from csv to a database without converting to scientific notation in VBAPhpmyadmin cannot read scientific notations in csv fileReading from CSV with value numbers formatted
QGIS Linestring rendering curves between vertex
Can I intentionally omit previous work experience or pretend it doesn't exist when applying for jobs?
The monorail explodes before I can get on it
Why do they not say "The Baby"
Interpreting the word "randomly"
When did the Roman Empire fall according to contemporaries?
latinate or other words of foreign origin as opposed to Germanic words
nmcheck.gnome.org facilitating ads?
Do native speakers use ZVE or CPU?
P-MOSFET failing
wavelength of seismic wave with a gaussian source
Find the wrong number in the given series: 6, 12, 21, 36, 56, 81?
What's the point of this scene involving Flash Thompson at the airport?
Why hasn't the U.S. government paid war reparations to any country it attacked?
Can I call 112 to check a police officer's identity in the Czech Republic?
What to put after taking off rear stabilisers from child bicyle?
How many matrices satisfy this equality?
Hacker Rank : Electronics Shop
School House Points (Python + SQLite)
A DVR algebra with weird automorphisms
Why did my rum cake turn black?
Is a public company able to check out who owns its shares in very detailed format?
Players of unusual orchestral instruments
Was the Ford Model T black because of the speed black paint dries?
Converting Scientific notation values into numeric one while reading csv file which is serialized automatically
Convert numbers with exponential notation from string to double or decimalCSV file Read in PythonIn C#, how can I create a TextReader object from a string (without writing to disk)Python: Convert string (in scientific notation) to floatHow can I convert scientific notation to text from CSV file using PHPconvert scientific notation number into normal number by php?How To Parse a Scientific Notation Value Back To Original Value When Reading CSV In C#Convert Scientific notation to decimal in csvHow to import long number from csv to a database without converting to scientific notation in VBAPhpmyadmin cannot read scientific notations in csv fileReading from CSV with value numbers formatted
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I have a csv file which I have to import into data base. When reading the file by stream reader, some values are converted into scientific notation like "5.00E+11". I have to restore this into original values. This is being done by a job, so I can not format the cell to "text" or "special" manually. When that cell is formatted as "text" or "special" it is working fine.
I need result as follows :
"5.00E+11" should be converted into "500000000000"
"8.12E+12" should be converted into "8122280000000"
My code for reading the file is as below:
/// <summary>
/// This is used to read the csv file
/// </summary>
using (StreamReader reader = new StreamReader(comepleteFilePath))
values = reader.ReadToEnd()
.Split(new string[]
Environment.NewLine ,
StringSplitOptions.RemoveEmptyEntries
).ToList();
var _tempNuber = Convert.ToString(splits[13].Trim());
like below
c# csv console-application inputstreamreader
add a comment |
I have a csv file which I have to import into data base. When reading the file by stream reader, some values are converted into scientific notation like "5.00E+11". I have to restore this into original values. This is being done by a job, so I can not format the cell to "text" or "special" manually. When that cell is formatted as "text" or "special" it is working fine.
I need result as follows :
"5.00E+11" should be converted into "500000000000"
"8.12E+12" should be converted into "8122280000000"
My code for reading the file is as below:
/// <summary>
/// This is used to read the csv file
/// </summary>
using (StreamReader reader = new StreamReader(comepleteFilePath))
values = reader.ReadToEnd()
.Split(new string[]
Environment.NewLine ,
StringSplitOptions.RemoveEmptyEntries
).ToList();
var _tempNuber = Convert.ToString(splits[13].Trim());
like below
c# csv console-application inputstreamreader
1
Possible duplicate of Convert numbers with exponential notation from string to double or decimal
– Chetan Ranpariya
Mar 26 at 5:45
Not duplicate exactly, it is issue of reading values which is serialized by excel automatically and same field have different type of data as well.
– Satish Chandra Maurya
Mar 26 at 6:21
add a comment |
I have a csv file which I have to import into data base. When reading the file by stream reader, some values are converted into scientific notation like "5.00E+11". I have to restore this into original values. This is being done by a job, so I can not format the cell to "text" or "special" manually. When that cell is formatted as "text" or "special" it is working fine.
I need result as follows :
"5.00E+11" should be converted into "500000000000"
"8.12E+12" should be converted into "8122280000000"
My code for reading the file is as below:
/// <summary>
/// This is used to read the csv file
/// </summary>
using (StreamReader reader = new StreamReader(comepleteFilePath))
values = reader.ReadToEnd()
.Split(new string[]
Environment.NewLine ,
StringSplitOptions.RemoveEmptyEntries
).ToList();
var _tempNuber = Convert.ToString(splits[13].Trim());
like below
c# csv console-application inputstreamreader
I have a csv file which I have to import into data base. When reading the file by stream reader, some values are converted into scientific notation like "5.00E+11". I have to restore this into original values. This is being done by a job, so I can not format the cell to "text" or "special" manually. When that cell is formatted as "text" or "special" it is working fine.
I need result as follows :
"5.00E+11" should be converted into "500000000000"
"8.12E+12" should be converted into "8122280000000"
My code for reading the file is as below:
/// <summary>
/// This is used to read the csv file
/// </summary>
using (StreamReader reader = new StreamReader(comepleteFilePath))
values = reader.ReadToEnd()
.Split(new string[]
Environment.NewLine ,
StringSplitOptions.RemoveEmptyEntries
).ToList();
var _tempNuber = Convert.ToString(splits[13].Trim());
like below
c# csv console-application inputstreamreader
c# csv console-application inputstreamreader
edited Mar 27 at 12:33
Prasad Telkikar
4,0492 gold badges8 silver badges27 bronze badges
4,0492 gold badges8 silver badges27 bronze badges
asked Mar 26 at 5:40
Satish Chandra MauryaSatish Chandra Maurya
36 bronze badges
36 bronze badges
1
Possible duplicate of Convert numbers with exponential notation from string to double or decimal
– Chetan Ranpariya
Mar 26 at 5:45
Not duplicate exactly, it is issue of reading values which is serialized by excel automatically and same field have different type of data as well.
– Satish Chandra Maurya
Mar 26 at 6:21
add a comment |
1
Possible duplicate of Convert numbers with exponential notation from string to double or decimal
– Chetan Ranpariya
Mar 26 at 5:45
Not duplicate exactly, it is issue of reading values which is serialized by excel automatically and same field have different type of data as well.
– Satish Chandra Maurya
Mar 26 at 6:21
1
1
Possible duplicate of Convert numbers with exponential notation from string to double or decimal
– Chetan Ranpariya
Mar 26 at 5:45
Possible duplicate of Convert numbers with exponential notation from string to double or decimal
– Chetan Ranpariya
Mar 26 at 5:45
Not duplicate exactly, it is issue of reading values which is serialized by excel automatically and same field have different type of data as well.
– Satish Chandra Maurya
Mar 26 at 6:21
Not duplicate exactly, it is issue of reading values which is serialized by excel automatically and same field have different type of data as well.
– Satish Chandra Maurya
Mar 26 at 6:21
add a comment |
3 Answers
3
active
oldest
votes
Firstly, you should use a dedicated CSV parser like CsvHelper, this will potentially save you a lot of time.
Secondly, if you want to parse a number use something like decimal
, or double
Parse
with one of the options. In this case NumberStyles.Float
decimal.Parse(number, NumberStyles.Float);
NumberStyles.Float
Indicates that the
AllowLeadingWhite
,AllowTrailingWhite
,
AllowLeadingSign
,AllowDecimalPoint
, andAllowExponent
styles are
used. This is a composite number style.
AllowExponent
Indicates that the numeric string can be in exponential notation. The
AllowExponent flag allows the parsed string to contain an exponent
that begins with the "E" or "e" character and that is followed by an
optional positive or negative sign and an integer. In other words, it
successfully parses strings in the form nnnExx, nnnE+xx, and nnnE-xx.
It does not allow a decimal separator or sign in the significand or
mantissa; to allow these elements in the string to be parsed, use the
AllowDecimalPoint and AllowLeadingSign flags, or use a composite style
that includes these individual flags.
Update
you can either use regex to try and determine if the field does contain an actual number. Like d.d+E[+-]d+
or even better just use decminal.TryParse
with the appropriate options.
That field is not only numeric; some data are text and some are numeric and some are combination of both text and numeric so I can not hard code any formatter directly. Issue are only with large numeric values.
– Satish Chandra Maurya
Mar 26 at 5:56
@SatishChandraMaurya updated
– TheGeneral
Mar 26 at 6:01
I have to check if it is a numeric value and in scientific notation as well then have to use : decimal.Parse(number, NumberStyles.Float);
– Satish Chandra Maurya
Mar 26 at 6:10
@SatishChandraMauryadecminal.TryParse
will do both
– TheGeneral
Mar 26 at 6:13
add a comment |
You can parse that string to decimal
string s = "5.00E+11";
decimal d = decimal.Parse(s, NumberStyles.Float);
Output
500000000000
If you want to apply parsing only one exponential element, then you can check given string is exponential or not
double d = 0;
if(str.Contains("E") && double.TryParse(str, out d))
//Your conversion
POC : .net fiddle
Ya that's working fine.
– Satish Chandra Maurya
Mar 26 at 6:21
I can not check for "E" since a text value might contain that character also. So I have to check for "+" char instead of that ie. str.Contains("+")
– Satish Chandra Maurya
Mar 26 at 6:42
I have additional condition check ofTryParse
that is important to check that passed string is of double type and Exp number always contains+ and E/e
– Prasad Telkikar
Mar 26 at 6:45
add a comment |
Check if that field is numeric and in scientific notation as well then format as :
var _tempNuber = splits[13].Trim().Contains('+') ? decimal.Parse(splits[13].Trim(), NumberStyles.Float).ToString()
: splits[13].Trim();
What ifsplits[13]
contains something like1+2
– Prasad Telkikar
Mar 26 at 6:38
No chance since no special characters are allowed there
– Satish Chandra Maurya
Mar 26 at 7:10
Your last comment is contradictory as you mentioned exponential number in question (it contains+
in string) and in last statement you said no special characters... I don;t khow what values present insplits[13]
, but solution suggested by you in an answer is not sustainable (I believe) if it works for you then I am happy about your answer
– Prasad Telkikar
Mar 26 at 7:15
@Prasad let me clear; In database table from where the data is exported into the csv file, special characters are not allowed into that column from front end of the application. Now in Cell[13] of csv file the value is "500000000000" but when I read that field by above code, it is being read as "5.00E+11" due to automatic serialization of excel automatically.
– Satish Chandra Maurya
Mar 28 at 9:27
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55350500%2fconverting-scientific-notation-values-into-numeric-one-while-reading-csv-file-wh%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
Firstly, you should use a dedicated CSV parser like CsvHelper, this will potentially save you a lot of time.
Secondly, if you want to parse a number use something like decimal
, or double
Parse
with one of the options. In this case NumberStyles.Float
decimal.Parse(number, NumberStyles.Float);
NumberStyles.Float
Indicates that the
AllowLeadingWhite
,AllowTrailingWhite
,
AllowLeadingSign
,AllowDecimalPoint
, andAllowExponent
styles are
used. This is a composite number style.
AllowExponent
Indicates that the numeric string can be in exponential notation. The
AllowExponent flag allows the parsed string to contain an exponent
that begins with the "E" or "e" character and that is followed by an
optional positive or negative sign and an integer. In other words, it
successfully parses strings in the form nnnExx, nnnE+xx, and nnnE-xx.
It does not allow a decimal separator or sign in the significand or
mantissa; to allow these elements in the string to be parsed, use the
AllowDecimalPoint and AllowLeadingSign flags, or use a composite style
that includes these individual flags.
Update
you can either use regex to try and determine if the field does contain an actual number. Like d.d+E[+-]d+
or even better just use decminal.TryParse
with the appropriate options.
That field is not only numeric; some data are text and some are numeric and some are combination of both text and numeric so I can not hard code any formatter directly. Issue are only with large numeric values.
– Satish Chandra Maurya
Mar 26 at 5:56
@SatishChandraMaurya updated
– TheGeneral
Mar 26 at 6:01
I have to check if it is a numeric value and in scientific notation as well then have to use : decimal.Parse(number, NumberStyles.Float);
– Satish Chandra Maurya
Mar 26 at 6:10
@SatishChandraMauryadecminal.TryParse
will do both
– TheGeneral
Mar 26 at 6:13
add a comment |
Firstly, you should use a dedicated CSV parser like CsvHelper, this will potentially save you a lot of time.
Secondly, if you want to parse a number use something like decimal
, or double
Parse
with one of the options. In this case NumberStyles.Float
decimal.Parse(number, NumberStyles.Float);
NumberStyles.Float
Indicates that the
AllowLeadingWhite
,AllowTrailingWhite
,
AllowLeadingSign
,AllowDecimalPoint
, andAllowExponent
styles are
used. This is a composite number style.
AllowExponent
Indicates that the numeric string can be in exponential notation. The
AllowExponent flag allows the parsed string to contain an exponent
that begins with the "E" or "e" character and that is followed by an
optional positive or negative sign and an integer. In other words, it
successfully parses strings in the form nnnExx, nnnE+xx, and nnnE-xx.
It does not allow a decimal separator or sign in the significand or
mantissa; to allow these elements in the string to be parsed, use the
AllowDecimalPoint and AllowLeadingSign flags, or use a composite style
that includes these individual flags.
Update
you can either use regex to try and determine if the field does contain an actual number. Like d.d+E[+-]d+
or even better just use decminal.TryParse
with the appropriate options.
That field is not only numeric; some data are text and some are numeric and some are combination of both text and numeric so I can not hard code any formatter directly. Issue are only with large numeric values.
– Satish Chandra Maurya
Mar 26 at 5:56
@SatishChandraMaurya updated
– TheGeneral
Mar 26 at 6:01
I have to check if it is a numeric value and in scientific notation as well then have to use : decimal.Parse(number, NumberStyles.Float);
– Satish Chandra Maurya
Mar 26 at 6:10
@SatishChandraMauryadecminal.TryParse
will do both
– TheGeneral
Mar 26 at 6:13
add a comment |
Firstly, you should use a dedicated CSV parser like CsvHelper, this will potentially save you a lot of time.
Secondly, if you want to parse a number use something like decimal
, or double
Parse
with one of the options. In this case NumberStyles.Float
decimal.Parse(number, NumberStyles.Float);
NumberStyles.Float
Indicates that the
AllowLeadingWhite
,AllowTrailingWhite
,
AllowLeadingSign
,AllowDecimalPoint
, andAllowExponent
styles are
used. This is a composite number style.
AllowExponent
Indicates that the numeric string can be in exponential notation. The
AllowExponent flag allows the parsed string to contain an exponent
that begins with the "E" or "e" character and that is followed by an
optional positive or negative sign and an integer. In other words, it
successfully parses strings in the form nnnExx, nnnE+xx, and nnnE-xx.
It does not allow a decimal separator or sign in the significand or
mantissa; to allow these elements in the string to be parsed, use the
AllowDecimalPoint and AllowLeadingSign flags, or use a composite style
that includes these individual flags.
Update
you can either use regex to try and determine if the field does contain an actual number. Like d.d+E[+-]d+
or even better just use decminal.TryParse
with the appropriate options.
Firstly, you should use a dedicated CSV parser like CsvHelper, this will potentially save you a lot of time.
Secondly, if you want to parse a number use something like decimal
, or double
Parse
with one of the options. In this case NumberStyles.Float
decimal.Parse(number, NumberStyles.Float);
NumberStyles.Float
Indicates that the
AllowLeadingWhite
,AllowTrailingWhite
,
AllowLeadingSign
,AllowDecimalPoint
, andAllowExponent
styles are
used. This is a composite number style.
AllowExponent
Indicates that the numeric string can be in exponential notation. The
AllowExponent flag allows the parsed string to contain an exponent
that begins with the "E" or "e" character and that is followed by an
optional positive or negative sign and an integer. In other words, it
successfully parses strings in the form nnnExx, nnnE+xx, and nnnE-xx.
It does not allow a decimal separator or sign in the significand or
mantissa; to allow these elements in the string to be parsed, use the
AllowDecimalPoint and AllowLeadingSign flags, or use a composite style
that includes these individual flags.
Update
you can either use regex to try and determine if the field does contain an actual number. Like d.d+E[+-]d+
or even better just use decminal.TryParse
with the appropriate options.
edited Mar 26 at 6:01
answered Mar 26 at 5:46
TheGeneralTheGeneral
42.1k8 gold badges46 silver badges75 bronze badges
42.1k8 gold badges46 silver badges75 bronze badges
That field is not only numeric; some data are text and some are numeric and some are combination of both text and numeric so I can not hard code any formatter directly. Issue are only with large numeric values.
– Satish Chandra Maurya
Mar 26 at 5:56
@SatishChandraMaurya updated
– TheGeneral
Mar 26 at 6:01
I have to check if it is a numeric value and in scientific notation as well then have to use : decimal.Parse(number, NumberStyles.Float);
– Satish Chandra Maurya
Mar 26 at 6:10
@SatishChandraMauryadecminal.TryParse
will do both
– TheGeneral
Mar 26 at 6:13
add a comment |
That field is not only numeric; some data are text and some are numeric and some are combination of both text and numeric so I can not hard code any formatter directly. Issue are only with large numeric values.
– Satish Chandra Maurya
Mar 26 at 5:56
@SatishChandraMaurya updated
– TheGeneral
Mar 26 at 6:01
I have to check if it is a numeric value and in scientific notation as well then have to use : decimal.Parse(number, NumberStyles.Float);
– Satish Chandra Maurya
Mar 26 at 6:10
@SatishChandraMauryadecminal.TryParse
will do both
– TheGeneral
Mar 26 at 6:13
That field is not only numeric; some data are text and some are numeric and some are combination of both text and numeric so I can not hard code any formatter directly. Issue are only with large numeric values.
– Satish Chandra Maurya
Mar 26 at 5:56
That field is not only numeric; some data are text and some are numeric and some are combination of both text and numeric so I can not hard code any formatter directly. Issue are only with large numeric values.
– Satish Chandra Maurya
Mar 26 at 5:56
@SatishChandraMaurya updated
– TheGeneral
Mar 26 at 6:01
@SatishChandraMaurya updated
– TheGeneral
Mar 26 at 6:01
I have to check if it is a numeric value and in scientific notation as well then have to use : decimal.Parse(number, NumberStyles.Float);
– Satish Chandra Maurya
Mar 26 at 6:10
I have to check if it is a numeric value and in scientific notation as well then have to use : decimal.Parse(number, NumberStyles.Float);
– Satish Chandra Maurya
Mar 26 at 6:10
@SatishChandraMaurya
decminal.TryParse
will do both– TheGeneral
Mar 26 at 6:13
@SatishChandraMaurya
decminal.TryParse
will do both– TheGeneral
Mar 26 at 6:13
add a comment |
You can parse that string to decimal
string s = "5.00E+11";
decimal d = decimal.Parse(s, NumberStyles.Float);
Output
500000000000
If you want to apply parsing only one exponential element, then you can check given string is exponential or not
double d = 0;
if(str.Contains("E") && double.TryParse(str, out d))
//Your conversion
POC : .net fiddle
Ya that's working fine.
– Satish Chandra Maurya
Mar 26 at 6:21
I can not check for "E" since a text value might contain that character also. So I have to check for "+" char instead of that ie. str.Contains("+")
– Satish Chandra Maurya
Mar 26 at 6:42
I have additional condition check ofTryParse
that is important to check that passed string is of double type and Exp number always contains+ and E/e
– Prasad Telkikar
Mar 26 at 6:45
add a comment |
You can parse that string to decimal
string s = "5.00E+11";
decimal d = decimal.Parse(s, NumberStyles.Float);
Output
500000000000
If you want to apply parsing only one exponential element, then you can check given string is exponential or not
double d = 0;
if(str.Contains("E") && double.TryParse(str, out d))
//Your conversion
POC : .net fiddle
Ya that's working fine.
– Satish Chandra Maurya
Mar 26 at 6:21
I can not check for "E" since a text value might contain that character also. So I have to check for "+" char instead of that ie. str.Contains("+")
– Satish Chandra Maurya
Mar 26 at 6:42
I have additional condition check ofTryParse
that is important to check that passed string is of double type and Exp number always contains+ and E/e
– Prasad Telkikar
Mar 26 at 6:45
add a comment |
You can parse that string to decimal
string s = "5.00E+11";
decimal d = decimal.Parse(s, NumberStyles.Float);
Output
500000000000
If you want to apply parsing only one exponential element, then you can check given string is exponential or not
double d = 0;
if(str.Contains("E") && double.TryParse(str, out d))
//Your conversion
POC : .net fiddle
You can parse that string to decimal
string s = "5.00E+11";
decimal d = decimal.Parse(s, NumberStyles.Float);
Output
500000000000
If you want to apply parsing only one exponential element, then you can check given string is exponential or not
double d = 0;
if(str.Contains("E") && double.TryParse(str, out d))
//Your conversion
POC : .net fiddle
edited Mar 26 at 6:07
answered Mar 26 at 5:44
Prasad TelkikarPrasad Telkikar
4,0492 gold badges8 silver badges27 bronze badges
4,0492 gold badges8 silver badges27 bronze badges
Ya that's working fine.
– Satish Chandra Maurya
Mar 26 at 6:21
I can not check for "E" since a text value might contain that character also. So I have to check for "+" char instead of that ie. str.Contains("+")
– Satish Chandra Maurya
Mar 26 at 6:42
I have additional condition check ofTryParse
that is important to check that passed string is of double type and Exp number always contains+ and E/e
– Prasad Telkikar
Mar 26 at 6:45
add a comment |
Ya that's working fine.
– Satish Chandra Maurya
Mar 26 at 6:21
I can not check for "E" since a text value might contain that character also. So I have to check for "+" char instead of that ie. str.Contains("+")
– Satish Chandra Maurya
Mar 26 at 6:42
I have additional condition check ofTryParse
that is important to check that passed string is of double type and Exp number always contains+ and E/e
– Prasad Telkikar
Mar 26 at 6:45
Ya that's working fine.
– Satish Chandra Maurya
Mar 26 at 6:21
Ya that's working fine.
– Satish Chandra Maurya
Mar 26 at 6:21
I can not check for "E" since a text value might contain that character also. So I have to check for "+" char instead of that ie. str.Contains("+")
– Satish Chandra Maurya
Mar 26 at 6:42
I can not check for "E" since a text value might contain that character also. So I have to check for "+" char instead of that ie. str.Contains("+")
– Satish Chandra Maurya
Mar 26 at 6:42
I have additional condition check of
TryParse
that is important to check that passed string is of double type and Exp number always contains + and E/e
– Prasad Telkikar
Mar 26 at 6:45
I have additional condition check of
TryParse
that is important to check that passed string is of double type and Exp number always contains + and E/e
– Prasad Telkikar
Mar 26 at 6:45
add a comment |
Check if that field is numeric and in scientific notation as well then format as :
var _tempNuber = splits[13].Trim().Contains('+') ? decimal.Parse(splits[13].Trim(), NumberStyles.Float).ToString()
: splits[13].Trim();
What ifsplits[13]
contains something like1+2
– Prasad Telkikar
Mar 26 at 6:38
No chance since no special characters are allowed there
– Satish Chandra Maurya
Mar 26 at 7:10
Your last comment is contradictory as you mentioned exponential number in question (it contains+
in string) and in last statement you said no special characters... I don;t khow what values present insplits[13]
, but solution suggested by you in an answer is not sustainable (I believe) if it works for you then I am happy about your answer
– Prasad Telkikar
Mar 26 at 7:15
@Prasad let me clear; In database table from where the data is exported into the csv file, special characters are not allowed into that column from front end of the application. Now in Cell[13] of csv file the value is "500000000000" but when I read that field by above code, it is being read as "5.00E+11" due to automatic serialization of excel automatically.
– Satish Chandra Maurya
Mar 28 at 9:27
add a comment |
Check if that field is numeric and in scientific notation as well then format as :
var _tempNuber = splits[13].Trim().Contains('+') ? decimal.Parse(splits[13].Trim(), NumberStyles.Float).ToString()
: splits[13].Trim();
What ifsplits[13]
contains something like1+2
– Prasad Telkikar
Mar 26 at 6:38
No chance since no special characters are allowed there
– Satish Chandra Maurya
Mar 26 at 7:10
Your last comment is contradictory as you mentioned exponential number in question (it contains+
in string) and in last statement you said no special characters... I don;t khow what values present insplits[13]
, but solution suggested by you in an answer is not sustainable (I believe) if it works for you then I am happy about your answer
– Prasad Telkikar
Mar 26 at 7:15
@Prasad let me clear; In database table from where the data is exported into the csv file, special characters are not allowed into that column from front end of the application. Now in Cell[13] of csv file the value is "500000000000" but when I read that field by above code, it is being read as "5.00E+11" due to automatic serialization of excel automatically.
– Satish Chandra Maurya
Mar 28 at 9:27
add a comment |
Check if that field is numeric and in scientific notation as well then format as :
var _tempNuber = splits[13].Trim().Contains('+') ? decimal.Parse(splits[13].Trim(), NumberStyles.Float).ToString()
: splits[13].Trim();
Check if that field is numeric and in scientific notation as well then format as :
var _tempNuber = splits[13].Trim().Contains('+') ? decimal.Parse(splits[13].Trim(), NumberStyles.Float).ToString()
: splits[13].Trim();
answered Mar 26 at 6:33
Satish Chandra MauryaSatish Chandra Maurya
36 bronze badges
36 bronze badges
What ifsplits[13]
contains something like1+2
– Prasad Telkikar
Mar 26 at 6:38
No chance since no special characters are allowed there
– Satish Chandra Maurya
Mar 26 at 7:10
Your last comment is contradictory as you mentioned exponential number in question (it contains+
in string) and in last statement you said no special characters... I don;t khow what values present insplits[13]
, but solution suggested by you in an answer is not sustainable (I believe) if it works for you then I am happy about your answer
– Prasad Telkikar
Mar 26 at 7:15
@Prasad let me clear; In database table from where the data is exported into the csv file, special characters are not allowed into that column from front end of the application. Now in Cell[13] of csv file the value is "500000000000" but when I read that field by above code, it is being read as "5.00E+11" due to automatic serialization of excel automatically.
– Satish Chandra Maurya
Mar 28 at 9:27
add a comment |
What ifsplits[13]
contains something like1+2
– Prasad Telkikar
Mar 26 at 6:38
No chance since no special characters are allowed there
– Satish Chandra Maurya
Mar 26 at 7:10
Your last comment is contradictory as you mentioned exponential number in question (it contains+
in string) and in last statement you said no special characters... I don;t khow what values present insplits[13]
, but solution suggested by you in an answer is not sustainable (I believe) if it works for you then I am happy about your answer
– Prasad Telkikar
Mar 26 at 7:15
@Prasad let me clear; In database table from where the data is exported into the csv file, special characters are not allowed into that column from front end of the application. Now in Cell[13] of csv file the value is "500000000000" but when I read that field by above code, it is being read as "5.00E+11" due to automatic serialization of excel automatically.
– Satish Chandra Maurya
Mar 28 at 9:27
What if
splits[13]
contains something like 1+2
– Prasad Telkikar
Mar 26 at 6:38
What if
splits[13]
contains something like 1+2
– Prasad Telkikar
Mar 26 at 6:38
No chance since no special characters are allowed there
– Satish Chandra Maurya
Mar 26 at 7:10
No chance since no special characters are allowed there
– Satish Chandra Maurya
Mar 26 at 7:10
Your last comment is contradictory as you mentioned exponential number in question (it contains
+
in string) and in last statement you said no special characters... I don;t khow what values present in splits[13]
, but solution suggested by you in an answer is not sustainable (I believe) if it works for you then I am happy about your answer– Prasad Telkikar
Mar 26 at 7:15
Your last comment is contradictory as you mentioned exponential number in question (it contains
+
in string) and in last statement you said no special characters... I don;t khow what values present in splits[13]
, but solution suggested by you in an answer is not sustainable (I believe) if it works for you then I am happy about your answer– Prasad Telkikar
Mar 26 at 7:15
@Prasad let me clear; In database table from where the data is exported into the csv file, special characters are not allowed into that column from front end of the application. Now in Cell[13] of csv file the value is "500000000000" but when I read that field by above code, it is being read as "5.00E+11" due to automatic serialization of excel automatically.
– Satish Chandra Maurya
Mar 28 at 9:27
@Prasad let me clear; In database table from where the data is exported into the csv file, special characters are not allowed into that column from front end of the application. Now in Cell[13] of csv file the value is "500000000000" but when I read that field by above code, it is being read as "5.00E+11" due to automatic serialization of excel automatically.
– Satish Chandra Maurya
Mar 28 at 9:27
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55350500%2fconverting-scientific-notation-values-into-numeric-one-while-reading-csv-file-wh%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Possible duplicate of Convert numbers with exponential notation from string to double or decimal
– Chetan Ranpariya
Mar 26 at 5:45
Not duplicate exactly, it is issue of reading values which is serialized by excel automatically and same field have different type of data as well.
– Satish Chandra Maurya
Mar 26 at 6:21