Logic app flow : JSON to SQL - How to cast easily STR to FLOAT with number like "1.456,05"

Gabriel466 1 Reputation point
2022-08-08T12:16:07.007+00:00

Hi,

I'm questionning about the most simple way to cast str like "1.456,05" where the dot is a thousand separator and the coma a decimal separator.

I have a Logic app Flow who call a cognitive service + send back a JSON + parse JSON + SQL server insert row (V2).

I cannot find a solution to resolve the cast problem for number who are up to 999 because of the dot .

I tried to do replace(".","") AND convert to float() at the same time in the Insert row forms but i cannot save my Logic app when i do it in that way.

The data must be send in a database to make further mathematics operation .

In all the method i used, i always have error like "cannot cast string to float"

Does anyone had to face this problem?

Azure Logic Apps
Azure Logic Apps
An Azure service that automates the access and use of data across clouds without writing code.
2,856 questions
SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
12,765 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Tom Phillips 17,716 Reputation points
    2022-08-08T12:24:37.98+00:00

    Assuming your language is set correctly to allow for comma for decimal you can do this:

    TRY_CONVERT(float, TRY_CONVERT(money,@floatstr,1))  
    
    0 comments No comments

  2. Viorel 112.5K Reputation points
    2022-08-08T12:29:39.37+00:00

    If comma is the decimal separator, then the next example seems to work:

    declare @string as varchar(max) = '1.456,05'  
      
    select cast( replace(replace(@string, '.', ''), ',', '.') as float)  
    

    You can use this cast in your insert.

    0 comments No comments