Issue with Splitting tect

Hi All, I’m getting an error while splitting a string because i have 2 scenarios 1 will come with decimals and another with without decimal. When decimal value comes it is working if it is a normal number it is throwing an error. Can anyone guide me how to write a condition to match both the values in Assign.

Val : 12.456 – it will work
val : 12 – it throws an error

Main.xaml (6.9 KB)

HI @Learner007

What is you expected output?

Regards
Sudharsan

grafik

@Sudharsan_Ka if my input is 12.456 or 15 i need output like 12 or 15 . I don’t want the decimal values. I have attached my code but it is working only for the input is like 12.345 , if i give input - 14 it throws an error

Hi,

Another approach:

val2 = Convert.ToInt32(System.Text.RegularExpressions.Regex.Match(Val1,@"^\d+").Value)

Regards,

1 Like

we showed you above how to handle e.g. with the truncate.
About your exception:
in the case of 15 - there is no dot present. Therefore the IndexOf will return -1 and this will confuse the substring method

hi @ppr is there any possibility to modify below code because i have used this in main code .

Convert.ToInt32(Val1.ToString().Substring(0,Val1.ToString().IndexOf(“.”)))

I’m using - C# here

Convert.ToInt32(Math.Truncate(Convert.ToDouble(Val1.ToString())));
Convert.ToInt32(Math.Truncate(Convert.ToDouble("12.456")));

1 Like

Thanks @Yoichi This is working perfectly

1 Like

Thanks @ppr

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.