Graphics

 View Only
Expand all | Collapse all

Numeric conversion - DIFFICULT!

Brandon Derry

Brandon Derry06-20-2018 17:35

Brandon Derry

Brandon Derry06-20-2018 17:38

  • 1.  Numeric conversion - DIFFICULT!

    Posted 06-04-2018 14:00
    I have a real head-scratcher here. In a ticker, I need to take a numeric value and do some conversions. An example of my beginning number is 105.09532. I need to multiply the numbers after the decimals by 32, then change the decimal to an apostrophe. The end number should look like 105'305 Is this at all possible?


  • 2.  RE: Numeric conversion - DIFFICULT!

    Posted 06-04-2018 17:27
    HI
    I'd do it script. Something like:

    dim myNumber as string = "105.09532" 'your number, assuming it's probably coming from a text box so doing it with strings
    dim parts as string() = myNumber.split(".") 'split your decimal bits from your whole bits. Assuming you will always have a decimal point

    dim rhs as double = val(parts(1))*32 'do your x32 for the decimal bit

    dim newNumber as double = cdbl(parts(0)) + rhs.tostring() 'assuming if by multiplying by 32 you need to add any carry to the whole bit

    dim newNumberAsString as string = newNumber.tostring().replace(".","'") 'put it all back into a string, remove the decimal point and replace with a '

    I've just written this and not tested it, but might help you out.

    Simon

    #XPression


  • 3.  RE: Numeric conversion - DIFFICULT!

    Posted 06-04-2018 20:28

    Doesn't seem to be working. However, the number 105.09532 is from data and will vary. Also, if it helps, in my scene, that number is named "NUMBER3"


    #XPression


  • 4.  RE: Numeric conversion - DIFFICULT!

    Posted 06-06-2018 04:11

    If your number string is always going to be the same length you could use visual logic and do something like this.


    #XPression


  • 5.  RE: Numeric conversion - DIFFICULT!

    Posted 06-07-2018 11:40
    Thank you!!!! It's working, kind of. Unfortunately the number string varies. Is there a way to use visual logic with varying number strings?
    #XPression


  • 6.  RE: Numeric conversion - DIFFICULT!

    Posted 06-07-2018 12:42

    I also prefer to do this with scripting, so I will just modify Simons code above. This should also do it regardless of the number of digits. I put this in onOnline.

    dim Number3 as xpBaseObject
    Self.GetObjectByName("Number3",Number3)

    dim parts as string() = Number3.Text.split(".")
    'split your decimal bits from your whole bits. Assuming you will always have a decimal point

    dim rhs as double = Cint(parts(1))*32
    'do your x32 for the decimal bit

    Number3.Text = parts(0) + "'" + Cstr(rhs)




    Hope this helps.
    Mike


    #XPression


  • 7.  RE: Numeric conversion - DIFFICULT!

    Posted 06-07-2018 15:36
    This seems to work. However, the scene has been changed to add more numbers that need converted. I now have:
    Number1
    Net Change1
    Number2
    Net Change2
    Number 3
    Net Change 3
    Number 4
    Net Change 4

    Also, is there a way to limit the amount of numbers following the ' sign?
    #XPression


  • 8.  RE: Numeric conversion - DIFFICULT!

    Posted 06-08-2018 13:39


    dim Number as xpBaseObject

    for i as integer = 1 to 4
    Self.GetObjectByName("Number",Number3)

    dim parts as string() = Number3.Text.split(".")
    'split your decimal bits from your whole bits. Assuming you will always have a decimal point

    dim rhs as double = Cint(parts(1))*32
    'do your x32 for the decimal bit

    Number3.Text = parts(0) + "'" + Cstr(rhs)


    #XPression


  • 9.  RE: Numeric conversion - DIFFICULT!

    Posted 06-08-2018 13:46
    You could put the above into a loop, or put it into OnSetText of each of the text objects:
    dim parts as string() = Text.split(".")
    dim rhs as double = Cint(parts(1))*32
    Text = parts(0) + "'" + Cstr(rhs.Substring(0,4))


    To limit the number of numbers after the ' sign, get a substring of rhs

    Number3.Text = parts(0) + "'" + Cstr(rhs.Substring(0,4)) ' where the second number is the max number of numbers


    Mike


    #XPression


  • 10.  RE: Numeric conversion - DIFFICULT!

    Posted 06-11-2018 10:02
    Mike -
    I tried this script in On Set Text, but when I compiled the script it gave me a message "3,0: BC30456 'Substring' is not a member of 'Double'
    #XPression


  • 11.  RE: Numeric conversion - DIFFICULT!

    Posted 06-11-2018 10:06
    And also, I'm not well versed on script writing... How would I put your 1st script in a loop?
    #XPression


  • 12.  RE: Numeric conversion - DIFFICULT!

    Posted 06-11-2018 12:59
    For the OnSetText, I needed to turn the double, rhs into a string first, then get a substring of that. Here is the updated code you could put in OnSetText.

    dim parts as string() = Text.split(".")
    dim rhs as double = Cint(parts(1))*32
    Text = parts(0) + "'" + Cstr(rhs).Substring(0,4)



    You also noted NumberX and Net ChangeX for each. If NumberX is the original and Net Change the updated number, to do a loop, ,you would have to do something like this. It could live in the onOnline of the scene.
    dim Number, NetChange as xpBaseObject
    for i as integer = 1 to 4

    Self.GetObjectByName("Number" + Cstr(i),Number)
    Self.GetObjectByName("Net Change" + Cstr(i),NetChange)

    dim parts as string() = Number.Text.split(".")
    dim rhs as double = Cint(parts(1))*32
    NetChange.Text = parts(0) + "'" + Cstr(rhs).Substring(0,4)

    Next


    You may want to comment this out if it doesnt work to see where it is getting stopped.


    This should help get you there.

    Mike
    #XPression


  • 13.  RE: Numeric conversion - DIFFICULT!

    Posted 06-13-2018 13:50
    Another question, is there a syntax so I can learn the properties of these functions and/or what scripting language is used for Xpression?
    #XPression


  • 14.  RE: Numeric conversion - DIFFICULT!

    Posted 06-13-2018 13:53
    And Mike - with the numbers I am using, NumberX and NetChangeX are different numbers. NumberX is the "Last Price" for a stock symbol. "NetChangeX" is the value of the difference of the Price change from the previous price. I get both values from datalinq on an RSS feed.
    #XPression


  • 15.  RE: Numeric conversion - DIFFICULT!

    Posted 06-13-2018 14:26
    For the most part, the "OnSetText" script is working. The only issue I see is when the numbers follow the decimal point are zeros, it converts back to a decimal value. When I apply the script to the "NetChange" (which is 0.09375), it omits the first zero and gives me 0'100 The number that should be displayed in the NetChange instance is 0'01
    #XPression


  • 16.  RE: Numeric conversion - DIFFICULT!

    Posted 06-18-2018 18:27

    Here is a visual logic one if you'd like to try it 

    (broken image)


    #XPression


  • 17.  RE: Numeric conversion - DIFFICULT!

    Posted 06-20-2018 11:50
    bderry -

    I can't see the image. Can you please re-upload it?
    #XPression


  • 18.  RE: Numeric conversion - DIFFICULT!

    Posted 06-20-2018 17:35
    Here you go
    #XPression


  • 19.  RE: Numeric conversion - DIFFICULT!

    Posted 06-20-2018 17:38
    Here you go!
    #XPression


  • 20.  RE: Numeric conversion - DIFFICULT!

    Posted 06-21-2018 13:35
    What values did you use for Format Float, String Value, Right String, Left String and Concatenate?
    #XPression