问题
I need to convert a string to float I need u-sql code.
the script could be an exponencial like 10^2
I tried Float.Convert but not works.
I expect
convert(10^2) = 100
回答1:
Assuming this is your own format is You will need to write a C# function to do that.
You can write code behind
https://www.purplefrogsystems.com/paul/2017/04/calling-u-sql-stored-procedures-with-c-code-behind/
or functions
https://sqlplayer.net/2017/10/functions-in-the-usql-the-hidden-gem-in-the-summer-2017-update/
回答2:
An example using U-SQL inline functions:
DECLARE @func Func <string,int?> = (s) =>{int x = Convert.ToInt32(s.Split('^')[0]); int y = Convert.ToInt32(s.Split('^')[1]); return x*y;};
DECLARE @inputFile string = @"\input\input36.csv";
DECLARE @outputFile string = @"\output\output.csv";
@input =
EXTRACT rowId int,
expo string
FROM @inputFile
USING Extractors.Csv();
@output =
SELECT *,
@func(expo) AS z
FROM @input;
OUTPUT @output
TO @outputFile
USING Outputters.Csv(quoting:false);
Using this sample file, I got these results:
来源:https://stackoverflow.com/questions/54112242/convert-string-to-float-with-exponencial-numbers