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 :
Finance | Project Operations, Human Resources, ...
Unanswered

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

(0) ShareShare
ReportReport
Posted on by 172

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)

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 > Finance | Project Operations, Human Resources, AX, GP, SL

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 858 Super User 2025 Season 2

#2
Sohaib Cheema Profile Picture

Sohaib Cheema 850 User Group Leader

#3
CA Neeraj Kumar Profile Picture

CA Neeraj Kumar 827

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans