Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX (Archived)

Convert string to real value with specific number of decimal digits

Posted on by 11,873

I have a string variable contain a real value , I need to convert string to real value with specific number of decimal digits i.e. not necessary 2 digits when I use str2num I cannot determine number of decimal digits and they are two digits by default  

*This post is locked for comments

  • maram fraij Profile Picture
    maram fraij 11,873 on at
    RE: Convert string to real value with specific number of decimal digits

    Ok Thank you again it is only used for testing purposes .

  • Mea_ Profile Picture
    Mea_ 60,278 on at
    RE: Convert string to real value with specific number of decimal digits

    Don't use it in your code instead of strFmt, I used it as an example. If you want to show more decimals use strFmt + num2str.

  • maram fraij Profile Picture
    maram fraij 11,873 on at
    RE: Convert string to real value with specific number of decimal digits

    When I use info(queryValue(yy)) all digits appear

    Thank you.

  • Verified answer
    Mea_ Profile Picture
    Mea_ 60,278 on at
    RE: Convert string to real value with specific number of decimal digits

    So that's exactly what I said.  strFmt shows you only 2 decimals, but if you use debugger to check value of yy variable you will see all decimals. Another options is to use  info(queryValue(yy)); to see actual value of the variable.

  • maram fraij Profile Picture
    maram fraij 11,873 on at
    RE: Convert string to real value with specific number of decimal digits

    I try to create new EDT with display no of digit 6 but the info gives me the same result

  • maram fraij Profile Picture
    maram fraij 11,873 on at
    RE: Convert string to real value with specific number of decimal digits

    I try to do test before writing the required code to handle the scenario I have

    The is the code

    real RealValue=99.3421111111;

           str strValue= num2str

           (

           RealValue,

           -1, // Minimum number of characters to output into the string.

           6, // Required number of digits to the right of the decimal.

           DecimalSeparator::Dot,    // 1

           ThousandSeparator::None  // 2

           );

           real yy=str2num_RU(strValue);

           info(strValue);        

           info(strfmt("%1",yy));

           info(strfmt("%1",RealValue));

    47527.Untitled.png

  • Mea_ Profile Picture
    Mea_ 60,278 on at
    RE: Convert string to real value with specific number of decimal digits

    Hi maram fraij,

    str2num does not round value to 2 decimals and should return you all decimals. However, it could be rounded later, could you please share code you using and explain why you think that it is rounded\truncated?

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans