Loading numbers from a text file changes their values

(3 posts) (2 voices)

Tags:

No tags yet.

  1. bluAndy

    enthusiast
    Joined: Oct '14
    Posts: 90

    Hi.

    I have a problem with loading some numbers (floats) from a text file.

    When I load the text file, a string is created containing everything there is in the file. The numbers are separated by a "Tab" and for every 8 numbers the row is changed (or line). I use "scan string" to retrieve each number and then I use "create string" to create a new string where the numbers are separated by only a space.

    When I use scan string, I tell the BB to scan for "float". The numbers from the file have up to only 4 decimals max.
    When the "scan string" retrieves a float, it adds the missing decimal to the end of each number by adding zeros. That wouldn't be a problem but it doesn't add zeros to every number, there are numbers to which it adds 99 or 01 to the end, and that changes the value of my number.

    Then I try to cut off the added numbers using "sub string" to retrieve only 4 decimals. There, 2 others things happen:

    Not all my numbers are "edited". Some are left with only 4 decimals.... others are still displayed with 6 decimals.
    And some of the numbers that are displayed with less decimals have the last one increased or decreased by 1.

    Is there a mistake I'm making when I make the conversions from string to float or when I try to cut off the extra decimals? Why are the values of the numbers changed?

    I attached the project to the post. Can someone help me retrieve the right numbers from my file?

    The numbers that are changed after cutting off the extra decimals are: 19.2746 -> 19.2745; 19.0318 -> 19.0317

    And those which aren't even edited (cut off the 2 extra decimals) are: 18.4626 -> 18.462601; 18.5671 -> 18.567101; 18.0554 -> 18.055401; 18.8026 -> 18.802601; 19.2317 -> 19.231701 etc.

    Please help...

    Attachments

    1. Sample_Project.mpexp (25.3 KB, 7 downloads) 2 years old
    WARNING: Files uploaded in the forums are not monitored by 3DVIA and therefore might contain content that is malicious or offensive. Download at your own risk
    Posted 2 years ago #
  2. iainB85

    Interplanetary Delivery Boy
    Joined: Jun '08
    Posts: 515

    Hello, I don't know all the specifics but I am sure your problem has to do with converting from strings to floats. Seeing how your end result is to display on a text panel, you shouldn't need to deal with float parameters here at all, completely avoiding the conversion issues.

    I attached an updated project which does what I think you wanted it to do. My only disclaimer for you is I did use two VSL functions in the schematic task to parse the VSL, as parsing text in schematic can get quite messy in my opinion

    However, even if you are only a schematic user and don't fully understand all of the VSL inside of the functions, you should still be able to reuse them in the future if you wish, they are quite handy.

    Let me know if anything in the project doesn't make sense, I tried to comment the code as much as possible.

    Attachments

    1. forumStringSeperator.mpexp (26.4 KB, 10 downloads) 2 years old
    WARNING: Files uploaded in the forums are not monitored by 3DVIA and therefore might contain content that is malicious or offensive. Download at your own risk
    Posted 2 years ago #
  3. bluAndy

    enthusiast
    Joined: Oct '14
    Posts: 90

    Thank you very much. The comments from the VSL were very explicit. I understood everything.

    Posted 2 years ago #

Reply

You must log in to post.