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.  Convert string to integer

    Employee
    Posted 02-27-2015 03:44

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

    Originally posted by: epetrou

    Hello,

    i have encountered a problem with my limited knowledge..I am trying to convert a string to integer so i can do some math calculations with other columns.

    I have the following sample static data :

    node:Static_Data
    bretype:core::Static Data
    editor:sortkey=54f047a0449e700b
    output:@40fe6c55598828e5/=
    prop:StaticData=<<EOX
    C30_POS Code,bonus9
    POS18446,"0"
    POS13264,"32,2"
    POS2572,"20,48"
    POS13264,"20,48"
    POS2572,"48,76"
    POS13264,"40"
    POS18446,"0"

    EOX
    editor:XY=200,460
    end:Static_Data

    and i am trying to convert them to integer using a simple code
    b9=bonus9.int()

    but i get an error message "Cant convert '32,2' to integer"

    i have been playing around with format but i cant find a working solution. Can you provide your always valuable input ?


  • 2.  RE: Convert string to integer

    Employee
    Posted 02-27-2015 06:02

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

    Originally posted by: ryeh

    Haha, a good example of international differences. We have to first "convert" the commas so it's in format more commonly used in the U.S. Try:
    b9 = bonus9.replace(",",".").int()

    And so if there were periods, you'd have to replace them with blanks, i.e. "".


  • 3.  RE: Convert string to integer

    Employee
    Posted 02-27-2015 06:09

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

    Originally posted by: epetrou

    It makes perfect sense what u say. However it gives the same error ("Cant convert '32.2' to integer")

    Maybe its because the type is string and it resembles a decimal number?


  • 4.  RE: Convert string to integer

    Employee
    Posted 02-27-2015 06:22

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

    Originally posted by: epetrou

    It works as double though !

    b9 = bonus9.replace(",",".").double()

    I want to later use these numbers for some math, to calculate commission numbers.I wont have any problem adding or multiplying integer number will i ?


  • 5.  RE: Convert string to integer

    Employee
    Posted 02-27-2015 18:28

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

    Originally posted by: ryeh

    Oh, right, of course! Sorry, I wasn't thinking. Yes, numbers with decimal places can't be converted to integers.

    If you're adding or multiplying, I would stick with doubles. You have a larger range that way.