You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
1.1 KiB
C#
48 lines
1.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
|
|
namespace EPSON_SOCKET
|
|
{
|
|
public class Utils
|
|
{
|
|
// 将值转成int32,空值不会报错.
|
|
public static int TryToInt32(string Text)
|
|
{
|
|
int result = 0;
|
|
try
|
|
{
|
|
if (String.IsNullOrEmpty(Text)) return result;
|
|
result = Convert.ToInt32(Text);
|
|
}
|
|
catch (Exception ex) { }
|
|
//Cleanup:
|
|
return result;
|
|
}
|
|
|
|
// 将值转成double,空值不会报错.
|
|
public static double TryToDouble(string Text)
|
|
{
|
|
double result = 0;
|
|
try
|
|
{
|
|
if (String.IsNullOrEmpty(Text)) return result;
|
|
result = Convert.ToDouble(Text);
|
|
}
|
|
catch (Exception ex) { }
|
|
//Cleanup:
|
|
return result;
|
|
}
|
|
|
|
// 将值转成double,空值不会报错.
|
|
public static float TryToFloat(string Text)
|
|
{
|
|
float result = (float)Utils.TryToDouble(Text);
|
|
//Cleanup:
|
|
return result;
|
|
}
|
|
|
|
}
|
|
}
|