web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Read exponential value as string from csv file

(0) ShareShare
ReportReport
Posted on by 1,027

Hi Experts,

I am working are reading data from a csv file placed in SFTP folder.

I am using System.IO.StreamReader to read data from SFTP

I could extract all the values of all columns in csv file except one which is in exponential format.

e.g 3.53E+14 ; But the actual cell value is 352985000000000


Is there any way in x++ to read the actual cell value instead of exponential value. Below is my sample code.

System.IO.Stream    dataStream;
dataStream = SFXConnector::downloadFile(address,port,username,password);

using (System.IO.StreamReader streamReader = new System.IO.StreamReader(dataStream))
{
    while(!streamReader.EndOfStream)
    {
       str dataLine = streamReader.ReadLine();
       container record = str2con(dataLine, ",", false);
       str securityNumber = conpeek(record,1);
    }
}

Thanks,

N.Sridhar

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    nmaenpaa Profile Picture
    101,160 Moderator on at
    RE: Read exponential value as string from csv file

    Sukrut is right. If you don't have any control over the external system, you need to discuss with someone who has.

    But still I feel like this whole issue could be just something you see in Excel if you view the file there with default formatting. And in the csv itself the number is in the correct format. Did you already double check this?

  • Suggested answer
    nmaenpaa Profile Picture
    101,160 Moderator on at
    RE: Read exponential value as string from csv file

    Then it's not possible to get the exact value.

    The field simply doesn't contain that information.

    However could you please double check one the file one more time. Did you open it in Notepad or Excel? Or do you really see this value in D365FO during the import? Usually this kind of formatting happens in Excel but it doesn't mean that the underlying file really did store the value in exponential format.

    If you need to convert "3.53E + 14" into a number, I think you need to write some simple string handling logic.

    An example of such logic would be:

    1) Read the string until you see "E". -> You will get "3.53". Convert it to a number (real)

    2) Read the number that comes after "E + " -> you will get 14

    3) Create the multiplier. Add as many zeros as you found in step 2 and put them behind "1". You will get "100000000000000". Convert it to a number.

    4) Perform the calculation: 3.53 * 100000000000000 = 353000000000000

  • Sridhar Narayanan Profile Picture
    1,027 on at
    RE: Read exponential value as string from csv file

    Hi Nikolaos,

    The CSV file is coming from another external system. Unfortunately I don't have any control over the external system.

    We have to consume the file sent by external system.

    Thanks.

  • Suggested answer
    nmaenpaa Profile Picture
    101,160 Moderator on at
    RE: Read exponential value as string from csv file

    Where is this CSV coming from? Is it possible to put the value into the field in correct format?

    Assuming your CSV really contains text value "3.53E + 14", I don't think there's any way to convert it back to 352985000000000, because there is not enough information included in the formatted value.

    The best you could get out of it is 353000000000000.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Andrés Arias – Community Spotlight

We are honored to recognize Andrés Arias as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Syed Haris Shah Profile Picture

Syed Haris Shah 9

#2
Martin Dráb Profile Picture

Martin Dráb 2 Most Valuable Professional

#2
Community Member Profile Picture

Community Member 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans