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!

1 Like

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().

1 Like

Omg, thank you!!

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

2 Likes

This topic was automatically closed after 14 days. New replies are no longer allowed.