Convert string to float with exponencial numbers

浪子不回头ぞ 提交于 2021-02-10 15:43:03

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!