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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested Answer

D365 F&O X++ CSV export values are converted into scientific notation or lose decimals in Excel

(3) ShareShare
ReportReport
Posted on by 198

I am working on a customization in Dynamics 365 Finance & Operations (D365 F&O) where I generate a CSV file using X++.

In debug mode, the values are correct:

National ID → 631067242E87

Amount → 100.50

However, after exporting to CSV and opening the file in Excel, the values are displayed incorrectly:

National ID is converted into scientific notation → 6.31E+95

Amount loses trailing zeros → 100.5 instead of 100.50

 

 

 

 

i am using this code
public void open(int _ban = 0)
{
    ttsabort;
    CIMMYTROCustomisationTable parameter = CIMMYTROCustomisationTable::find();
    if (parameter.CIMMYT_RequireZimbabweEcoCashPaymentfile)
    {
        LedgerJournalTrans ledgerJournalTrans;
        VendTable vendTable;
        DimensionAttributeValueCombination dimComb;
        DirPartyTable partyTable;
        DirPerson dirPerson;
        DirPersonName personName;
        DirPartyLocation partyLocation;
        LogisticsElectronicAddress address;
        TaxRegistration taxReg;
        str vendorMobile, firstName, lastName, nationalId, amountStr, line;
        System.IO.MemoryStream memoryStream = new System.IO.MemoryStream();
        System.IO.StreamWriter writer = new System.IO.StreamWriter(memoryStream, System.Text.Encoding::UTF8);
        // CSV header
        writer.WriteLine("Phone Number,Amount,First Name,Last Name,National ID,Additional Field1,Additional Field2,Additional Field3");
        while select ledgerJournalTrans
            where ledgerJournalTrans.JournalNum == ledgerJournalId
               && ledgerJournalTrans.PaymentStatus == CustVendPaymStatus::Confirmed
               && ledgerJournalTrans.OffsetAccountType == LedgerJournalACType::Bank
               && ledgerJournalTrans.PaymMode == "TR-MOBILE"
        {
            vendorMobile = "";
            firstName    = "";
            lastName     = "";
            nationalId   = "";
            // Vendor info
            dimComb     = DimensionAttributeValueCombination::find(ledgerJournalTrans.LedgerDimension);
            VendAccount vendAccount = dimComb.DisplayValue;
            vendTable   = VendTable::find(vendAccount);
            partyTable  = DirPartyTable::findRec(vendTable.Party);
            //  1. Find Primary Mobile Number (direct from LogisticsElectronicAddress)
            select firstonly address
                where address.Party == vendTable.Party
                   && address.Type == LogisticsElectronicAddressMethodType::Phone
                   && address.Locator != ""
                   && address.IsPrimary == NoYes::Yes;
            if (address.RecId)
            {
                vendorMobile = strKeep(address.Locator, '0123456789');
            }
            //  2. Find National ID (from TaxRegistration → DirPartyLocation)
            select firstonly partyLocation
                where partyLocation.Party == vendTable.Party
                   && partyLocation.IsPrimary == NoYes::Yes;
            if (partyLocation.RecId)
            {
                select firstonly taxReg
                    where taxReg.DirPartyLocation == partyLocation.RecId;
                if (taxReg.RecId && taxReg.RegistrationNumber)
                {
                    str allowedCharacters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 ";
                    nationalId = strKeep(taxReg.RegistrationNumber, allowedCharacters);
                }
            }
            //  3. Get Vendor Name
            dirPerson = DirPerson::find(partyTable.RecId);
            if (dirPerson.RecId)
            {
                select firstonly personName
                    where personName.Person == dirPerson.RecId;
                firstName = strKeep(personName.FirstName, 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz ');
                lastName  = strKeep(personName.LastName,  'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz ');
            }
            //  4. Amount
            real amount = ledgerJournalTrans.AmountCurDebit != 0 ? ledgerJournalTrans.AmountCurDebit : ledgerJournalTrans.AmountCurCredit;
            amountStr = num2str(amount, -1, 2, 1, 0);
            amountStr = strRem(amountStr, ",");
            //  5. Build CSV line
            line = strFmt("%1,%2,%3,%4,%5,,,",
                        vendorMobile,
                        amountStr,
                        firstName,
                        lastName,
                        nationalId);
            writer.WriteLine(line);
        }
        writer.Flush();
        memoryStream.Position = 0;
        str exportFileName = strFmt("%1.csv", ledgerJournalId);
        file::SendFileToUser(memoryStream, exportFileName);
    }
}
in exel i am getting like this
 
 

  •  

  •  

 

Categories:
I have the same question (0)
  • Suggested answer
    CA Neeraj Kumar Profile Picture
    5,135 Super User 2026 Season 1 on at
     
    Thanks for giving all the details about the problem statement.
     
    This is a very common issue when exporting CSV from D365 F&O / X++ and then opening it directly in Excel.

    🔎 Why It Happens
    1. Excel behavior (not X++ bug):
      • Excel auto-formats CSV fields when you open them.
      • Large numbers (like National ID) → displayed in scientific notation (6.31E+95).
      • Decimals (like 100.50) → Excel trims trailing zeros and shows 100.5.
    So even though the file has correct values, Excel interprets them differently.
    1. Debug mode vs CSV output:
      • In debug mode, your string values (nationalId, amountStr) are correct.
      • But Excel’s default parser does not respect formatting like "keep 2 decimals" or "treat as text."

    ✅ Solutions
    1. Wrap sensitive fields in double quotes

    Force Excel to treat them as text:
    nationalId = '"' + nationalId + '"';
    amountStr  = '"' + amountStr + '"';
    
    Output in CSV:
    "631067242E87","100.50"

    Excel will then import them as text and preserve formatting.

    2. Keep trailing decimals in amount
    Your current code:
    amountStr = num2str(amount, -1, 2, 1, 0);
    This already forces 2 decimals. But Excel trims 100.50 → 100.5.
     
    Fix by wrapping in quotes:
    amountStr = '"' + amountStr + '"';

    3. Alternative: Export in any text editor like notepad, notepad++.

    🔧 Your Fixed Code Snippet
    Update your line building part:
     
    amountStr = num2str(amount, -1, 2, 1, 0);
    amountStr = strRem(amountStr, ",");
    
    // Force Excel to treat as text
    amountStr  = '"' + amountStr + '"';
    nationalId = '"' + nationalId + '"';
    
    // Build CSV line
    line = strFmt("%1,%2,%3,%4,%5,,,",
                vendorMobile,
                amountStr,
                firstName,
                lastName,
                nationalId);
    
    👉 Best practice: always wrap text-like fields (IDs, codes, formatted numbers) in quotes when exporting to CSV, because Excel will otherwise reinterpret them.

    If this helped, please mark it as "Verified" for others facing the same issue Keep in mind that it is possible to mark more than one answer as verified
     
    Regards,
    Neeraj Kumar
  • Aditya Pal Profile Picture
    198 on at
     
    hi  thank you so much for reply 
    Output in CSV:
    "631067242E87","100.50"
     
    i have used this but sir what i want to achive is 631067242E87 and 100.50 without "" one
  • Suggested answer
    CA Neeraj Kumar Profile Picture
    5,135 Super User 2026 Season 1 on at
    Hi Aditya, 
     
    Could you please share a bit more about why CSV is a must for your current business requirement? If it’s only for opening in Excel, I’d suggest avoiding that approach, since Excel often changes the values automatically.
     
    A better way would be to create a new workbook in Excel (xlsx format), then import the CSV data using text import or Power Query, making sure the columns are set as Text. This way, the values will stay as they are.
     
    By default, Excel tries to convert values based on its own logic, unless the column format is defined as Text. That’s why you may be seeing unexpected changes.
     
    If your requirement is specifically to export and open the file directly in Excel, could you please explain a little more about the need? If you just want to review the values, opening the file in a text editor will display them exactly as they are.
     
    Another option is to copy the text from the CSV, paste it into Excel, and use the “Text to Column" feature with the format set to Text. This should preserve the values exactly as you expect.
    Regards, 
    Neeraj
  • Aditya Pal Profile Picture
    198 on at
      i want because this csv file is for bank file i have to update for bank
     
  • Aditya Pal Profile Picture
    198 on at
     this csv file is a bank file that is why we need 631067242E87,100.50 like this
  • Suggested answer
    CA Neeraj Kumar Profile Picture
    5,135 Super User 2026 Season 1 on at
    Hi Aditya, 
     
    Then you have already build the correct file, you just need to open in text editor not excel.. Bank will be able to read the current file with correct values if values are showing correct in text editor (notepad or notepad++) 
     
    Regards, 
    Neeraj
  • André Arnaud de Calavon Profile Picture
    304,708 Super User 2026 Season 1 on at
    Hi Aditya,

    Apart from opening the file in a notepad, you can also change the column definitions during the CSV import wizard. Then you can mark a column as being text and on another you can change the decimal and thousands separator. This is Excel functionality.
  • Aditya Pal Profile Picture
    198 on at
      hii can you suggest how can i achive this
  • Martin Dráb Profile Picture
    239,451 Most Valuable Professional on at
    To get into the wizard, open Excel, click Data > From Text/CSV and select a file.
  • Suggested answer
    André Arnaud de Calavon Profile Picture
    304,708 Super User 2026 Season 1 on at
    HI Aditya,

    After the steps provided by Martin, you can transform data. In the example below, the Comma is suggested, but actually the file has a point as decimal separator.
     
    If you then click Transform Data, you can choose the data type per column.
     
     
     
     
     
    For the change of the decimal settings, you can right click the column name, then choose Change type > Using locale...
    Then choose the language (region setting) that will manage the decimal (or date) format.
     
    After that, click Close & Load.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 593 Super User 2026 Season 1

#2
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 543

#3
CP04-islander Profile Picture

CP04-islander 430

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans