Converting text with negative values to numbers

I have an app where i want to show timeseries data. As my data is a list of list of numbers. The field is a text field. when i try to convert into number, the negative values are lost (ie. absolute value conversion)

[-0.097]
[-0.116]
[-0.07]
[-0.1376]
[-0.0931]

When i try to convert into numbers, it becomes:
0,097
0,116
0,07
0,1376
0,0931

I saw that @steveoster experienced the same issue Convert text (containing only numbers) to numbers - #6 by stevoster

Hey! Yep, sounds similar to my issue a while back. When you are converting each number you need first identify if it is a negative (by a …contains “-” argument somewhere) and then, if this condition is true, multiply your converted number by -1. Depending on how you do it, you could have two conditional steps in the conversion workflow - one runs if the ‘target’ number contains “-” and one of it does not contain “-”.

Hope this help!

Thanks for the reply @stevoster!

How did you run the conversion workflow, I saw that you mentioned you had a custom state for it but cannot wrap my head around how to implement it into the workflow :sweat_smile:

My current expression is:
ts_turnover_dev_median:item#1:split by (,) : each item converted to number

Where ts_turnover_dev_median:item#1 = [-0.0146, -0.0039, 0.0386, -0.0082, 0.034]

I can’t reproduce the issue. It works as expected for me. This is core functionality, so I’d expect lots of apps would be affected if it were broken.


Are the square brackets actually part of the text you’re running through the :converted to number operator? If so, that’s the issue. If Bubble doesn’t recognize the entire string as a number, it just plucks out what it recognizes as a number.

In fact, even if there’s white space before the negative number, Bubble doesn’t recognize the minus sign as part of the number, so it’s also good practice to run the text through the :trimmed operator first.

Aha, just noticed your 2nd post before hitting reply. I think you need to insert a :trimmed operator after the :split by().

Omg, thank you!!

I used both trimmed and getting rid of the brackets with find & replace. It did the trick!