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)

Convert string to real value with specific number of decimal digits

(0) ShareShare
ReportReport
Posted on by

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

I have the same question (0)
  • Mea_ Profile Picture
    60,284 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?

  • maram fraij Profile Picture
    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

  • maram fraij Profile Picture
    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

  • Verified answer
    Mea_ Profile Picture
    60,284 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
    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.

  • Mea_ Profile Picture
    60,284 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
    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 .

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…

Pallavi Phade – Community Spotlight

We are honored to recognize Pallavi Phade as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Tocauer Profile Picture

Martin Tocauer 4

#2
AlissonGodoy Profile Picture

AlissonGodoy 2

#2
Community Member Profile Picture

Community Member 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans