LAE

Welcome to the LAE community!  Please feel free to start a discussion in the discussion tab or join in a conversation.

Discussions

Members

Resources

Events

 View Only
  • 1.  Converting numeric to string

    Employee
    Posted 01-25-2012 08:23

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: jonathanm

    I am trying to convert a double numeric value to a string from which I want to extract the first four characters as a string and using the following code:

    testDate = InvPrintDate + 19000000
    testStr = str(testDate)
    if testDate == 0 then testStr = "00000101"
    testYear = substr(testStr,0,4)
    testMonth = substr(testStr,4,2)

    InvprintDate is a 7 digit date in the form "cyymmdd". However, when I execute this the string being returned is in scientific notation, for example an InvPrintDate with a value of 1080923.0 returns a string of "2.00809e+007" with testYear and testMonth being "2.00" and "80" respectively.

    Is there a way of forcing the "str" function to return the value "20080923"?

    Thanks

    Jonathan


  • 2.  RE: Converting numeric to string

    Employee
    Posted 01-25-2012 08:31

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: Tim Meagher

    Hey,

    You first need to convert the double to an int first, prior to converting to a string. Bear in mind that the int function will round double values to the nearest whole integer. However, if the input numbers are integer values anyway - just stored in a double type - then this shouldn't be of any concern.

    Tim.


  • 3.  RE: Converting numeric to string

    Employee
    Posted 01-25-2012 08:46

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: jonathanm

    Hi Tim

    Thank you so much. You're a star sir, that worked perfectly.

    All the best

    Jonathan