本文整理汇总了C#中NumberFormatInfo类的典型用法代码示例。如果您正苦于以下问题:C# NumberFormatInfo类的具体用法?C# NumberFormatInfo怎么用?C# NumberFormatInfo使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
NumberFormatInfo类属于命名空间,在下文中一共展示了NumberFormatInfo类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PosTest1
public bool PosTest1()
{
bool retVal = true;
// Add your scenario description here
TestLibrary.TestFramework.BeginScenario("PosTest1: Verify default value of property CurrencyGroupSeparator .");
try
{
NumberFormatInfo nfi = new NumberFormatInfo();
if (nfi.CurrencyGroupSeparator != ",")
{
TestLibrary.TestFramework.LogError("001.1", "Property CurrencyGroupSeparator Err .");
retVal = false;
}
}
catch (Exception e)
{
TestLibrary.TestFramework.LogError("001.2", "Unexpected exception: " + e);
TestLibrary.TestFramework.LogInformation(e.StackTrace);
retVal = false;
}
return retVal;
}
示例2: PosTest1
public bool PosTest1()
{
bool retVal = true;
TestLibrary.TestFramework.BeginScenario("PosTest1: Test the IFormatInfo parameter.");
try
{
string s1 = " #1345";
NumberFormatInfo n1 = new NumberFormatInfo();
n1.NegativeSign = "#";
int i1 = Int32.Parse(s1, n1);
if (i1 != -1345)
{
TestLibrary.TestFramework.LogError("001", "The result is not the value as expected. ");
retVal = false;
}
}
catch (Exception e)
{
TestLibrary.TestFramework.LogError("002", "Unexpected exception: " + e);
retVal = false;
}
return retVal;
}
示例3: runTest
public Boolean runTest()
{
Console.Error.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver " + s_strDtTmVer);
int iCountErrors = 0;
int iCountTestcases = 0;
String strLoc = "Loc_000oo";
String strBaseLoc = "Loc_0000oo_";
String strOut = null;
NumberFormatInfo nfi1 = new NumberFormatInfo();
nfi1.NegativeSign = "^";
UInt64[] in2TestValues = {UInt64.MinValue,
0,
5,
13,
101,
1000,
50000,
(ulong)Int32.MaxValue,
(ulong)Int64.MaxValue,
UInt64.MaxValue
};
String[] strResultGFormat1 = {"0",
"0",
"5",
"13",
"101",
"1000",
"50000",
"2147483647",
"9223372036854775807",
"18446744073709551615",
};
try {
strBaseLoc = "Loc_1100ds_";
for (int i=0; i < in2TestValues.Length;i++)
{
strLoc = strBaseLoc+ i.ToString();
iCountTestcases++;
strOut = in2TestValues[i].ToString(nfi1);
if(!strOut.Equals(strResultGFormat1[i]))
{
iCountErrors++;
Console.WriteLine(s_strTFAbbrev+ "Err_293qu! , i=="+i+" strOut=="+strOut);
}
}
} catch (Exception exc_general ) {
++iCountErrors;
Console.WriteLine(s_strTFAbbrev +" Error Err_8888yyy! strLoc=="+ strLoc +", exc_general=="+exc_general);
}
if ( iCountErrors == 0 )
{
Console.Error.WriteLine( "paSs. "+s_strTFPath +" "+s_strTFName+" ,iCountTestcases=="+iCountTestcases);
return true;
}
else
{
Console.Error.WriteLine("FAiL! "+s_strTFPath+" "+s_strTFName+" ,iCountErrors=="+iCountErrors+" , BugNums?: "+s_strActiveBugNums );
return false;
}
}
示例4: PosTest1
public bool PosTest1()
{
bool retVal = true;
// Add your scenario description here
TestLibrary.TestFramework.BeginScenario("PosTest1: Verify Ctor .");
try
{
NumberFormatInfo nfi = new NumberFormatInfo();
if (nfi == null)
{
TestLibrary.TestFramework.LogError("001.1", "Failed to instance a NumberFormatInfo type .");
retVal = false;
}
}
catch (Exception e)
{
TestLibrary.TestFramework.LogError("001.2", "Unexpected exception: " + e);
TestLibrary.TestFramework.LogInformation(e.StackTrace);
retVal = false;
}
return retVal;
}
示例5: DoPosTest
public bool DoPosTest(string testDesc, string id, UInt16 uintA, string format, String expectedValue, NumberFormatInfo _NFI)
{
bool retVal = true;
string errorDesc;
string actualValue;
TestLibrary.TestFramework.BeginScenario(testDesc);
try
{
actualValue = uintA.ToString(format, _NFI);
if (actualValue != expectedValue)
{
errorDesc =
string.Format("The string representation of {0} is not the value {1} as expected: actual({2})",
uintA, expectedValue, actualValue);
errorDesc += "\nThe format info is \"" + ((format == null) ? "null" : format) + "\" speicifed";
TestLibrary.TestFramework.LogError(id + "_001", errorDesc);
retVal = false;
}
}
catch (Exception e)
{
errorDesc = "Unexpect exception:" + e;
errorDesc += "\nThe UInt16 integer is " + uintA + ", format info is \"" + format + "\" speicifed.";
TestLibrary.TestFramework.LogError(id + "_002", errorDesc);
retVal = false;
}
return retVal;
}
示例6: PosTest1
public bool PosTest1()
{
bool retVal = true;
// Add your scenario description here
TestLibrary.TestFramework.BeginScenario("PosTest1: Verify method ReadOnly .");
try
{
NumberFormatInfo nfi = new NumberFormatInfo();
NumberFormatInfo nfiReadOnly = NumberFormatInfo.ReadOnly(nfi);
if (nfiReadOnly.IsReadOnly != true)
{
TestLibrary.TestFramework.LogError("001.1", "Method ReadOnly Err .");
retVal = false;
}
}
catch (Exception e)
{
TestLibrary.TestFramework.LogError("001.2", "Unexpected exception: " + e);
TestLibrary.TestFramework.LogInformation(e.StackTrace);
retVal = false;
}
return retVal;
}
示例7: PosTest1
public bool PosTest1()
{
bool retVal = true;
// Add your scenario description here
TestLibrary.TestFramework.BeginScenario("PosTest1: Verify method Clone .");
try
{
NumberFormatInfo nfi1 = new NumberFormatInfo();
NumberFormatInfo nfi2 = (NumberFormatInfo)nfi1.Clone();
if (!nfi1.Equals(nfi2) && nfi1.GetHashCode() == nfi2.GetHashCode())
{
TestLibrary.TestFramework.LogError("001.1", "Method Clone Err .");
retVal = false;
}
}
catch (Exception e)
{
TestLibrary.TestFramework.LogError("001", "Unexpected exception: " + e);
TestLibrary.TestFramework.LogInformation(e.StackTrace);
retVal = false;
}
return retVal;
}
示例8: PosTest2
public bool PosTest2()
{
bool retVal = true;
TestLibrary.TestFramework.BeginScenario("PosTest2: Test the string with white space in both the beginning and the end");
try
{
int i2 = TestLibrary.Generator.GetInt32(-55);
string s1 = " " + i2.ToString() + " ";
NumberFormatInfo n1 = new NumberFormatInfo();
n1.NegativeSign = "#";
int i1 = Int32.Parse(s1, n1);
if (i1 != i2)
{
TestLibrary.TestFramework.LogError("003", "The result is not the value as expected. ");
retVal = false;
}
}
catch (Exception e)
{
TestLibrary.TestFramework.LogError("004", "Unexpected exception: " + e);
retVal = false;
}
return retVal;
}
示例9: PosTest2
public bool PosTest2()
{
bool retVal = true;
// Add your scenario description here
TestLibrary.TestFramework.BeginScenario("PosTest2: Verify method GetFormat when arg is not a type of NumberFormatInfo .");
try
{
NumberFormatInfo nfi = new NumberFormatInfo();
Type formatType = typeof(object);
if (nfi.GetFormat(formatType) != null)
{
TestLibrary.TestFramework.LogError("002.1", "Failed to instance a NumberFormatInfo type .");
retVal = false;
}
}
catch (Exception e)
{
TestLibrary.TestFramework.LogError("002.2", "Unexpected exception: " + e);
TestLibrary.TestFramework.LogInformation(e.StackTrace);
retVal = false;
}
return retVal;
}
示例10: ReadOnly
public void ReadOnly(NumberFormatInfo format, bool expected)
{
Assert.Equal(expected, format.IsReadOnly);
NumberFormatInfo readOnlyFormat = NumberFormatInfo.ReadOnly(format);
Assert.True(readOnlyFormat.IsReadOnly);
}
示例11: PosTest1
public bool PosTest1()
{
bool retVal = true;
// Add your scenario description here
TestLibrary.TestFramework.BeginScenario("PosTest1: Verify method GetFormat when arg is a type of NumberFormatInfo .");
try
{
NumberFormatInfo nfi = new NumberFormatInfo();
Type formatType = typeof(NumberFormatInfo);
object obj = nfi.GetFormat(formatType);
bool testVerify = obj is NumberFormatInfo;
if (testVerify != true)
{
TestLibrary.TestFramework.LogError("001.1", "Method GetFormat .");
retVal = false;
}
}
catch (Exception e)
{
TestLibrary.TestFramework.LogError("001.2", "Unexpected exception: " + e);
TestLibrary.TestFramework.LogInformation(e.StackTrace);
retVal = false;
}
return retVal;
}
示例12: PosTest2
public bool PosTest2()
{
bool retVal = true;
// Add your scenario description here
TestLibrary.TestFramework.BeginScenario("PosTest2: Verify set value of property CurrencyDecimalSeparator .");
try
{
string testStr = "testStr";
NumberFormatInfo nfi = new NumberFormatInfo();
nfi.CurrencyDecimalSeparator = testStr;
if (nfi.CurrencyDecimalSeparator != testStr)
{
TestLibrary.TestFramework.LogError("002.1", "Property CurrencyDecimalSeparator Err .");
retVal = false;
}
}
catch (Exception e)
{
TestLibrary.TestFramework.LogError("002.2", "Unexpected exception: " + e);
TestLibrary.TestFramework.LogInformation(e.StackTrace);
retVal = false;
}
return retVal;
}
示例13: GetInstance
public void GetInstance(IFormatProvider formatProvider, NumberFormatInfo expected)
{
NumberFormatInfo nfi = NumberFormatInfo.GetInstance(formatProvider);
Assert.Equal(expected.CurrencyDecimalDigits, nfi.CurrencyDecimalDigits);
Assert.Equal(expected.CurrencyDecimalSeparator, nfi.CurrencyDecimalSeparator);
Assert.Equal(expected.CurrencyGroupSeparator, nfi.CurrencyGroupSeparator);
Assert.Equal(expected.CurrencyGroupSizes, nfi.CurrencyGroupSizes);
Assert.Equal(expected.CurrencyNegativePattern, nfi.CurrencyNegativePattern);
Assert.Equal(expected.CurrencyPositivePattern, nfi.CurrencyPositivePattern);
Assert.Equal(expected.CurrencySymbol, nfi.CurrencySymbol);
Assert.Equal(expected.NaNSymbol, nfi.NaNSymbol);
Assert.Equal(expected.NegativeInfinitySymbol, nfi.NegativeInfinitySymbol);
Assert.Equal(expected.NegativeSign, nfi.NegativeSign);
Assert.Equal(expected.NumberDecimalDigits, nfi.NumberDecimalDigits);
Assert.Equal(expected.NumberDecimalSeparator, nfi.NumberDecimalSeparator);
Assert.Equal(expected.NumberGroupSeparator, nfi.NumberGroupSeparator);
Assert.Equal(expected.NumberGroupSizes, nfi.NumberGroupSizes);
Assert.Equal(expected.NumberNegativePattern, nfi.NumberNegativePattern);
Assert.Equal(expected.PercentDecimalDigits, nfi.PercentDecimalDigits);
Assert.Equal(expected.PercentDecimalSeparator, nfi.PercentDecimalSeparator);
Assert.Equal(expected.PercentGroupSeparator, nfi.PercentGroupSeparator);
Assert.Equal(expected.PercentGroupSizes, nfi.PercentGroupSizes);
Assert.Equal(expected.PercentNegativePattern, nfi.PercentNegativePattern);
Assert.Equal(expected.PercentPositivePattern, nfi.PercentPositivePattern);
Assert.Equal(expected.PercentSymbol, nfi.PercentSymbol);
Assert.Equal(expected.PositiveInfinitySymbol, nfi.PositiveInfinitySymbol);
Assert.Equal(expected.PerMilleSymbol, nfi.PerMilleSymbol);
Assert.Equal(expected.PositiveSign, nfi.PositiveSign);
}
示例14: ToStrWithPoint
public static string ToStrWithPoint(this decimal? d)
{
var nfi = new NumberFormatInfo();
nfi.NumberDecimalSeparator = ".";
//nfi.NumberGroupSeparator = ".";
if (d.HasValue)
return d.Value.ToString(nfi);
return "";
}
示例15: NumberFormatInfo_Set_TestData
public static IEnumerable<object[]> NumberFormatInfo_Set_TestData()
{
NumberFormatInfo customNumberFormatInfo1 = new NumberFormatInfo();
customNumberFormatInfo1.NegativeInfinitySymbol = "a";
yield return new object[] { "en-US", customNumberFormatInfo1 };
NumberFormatInfo customNumberFormatInfo2 = new NumberFormatInfo();
customNumberFormatInfo2.PositiveSign = "b";
yield return new object[] { "fi-FI", customNumberFormatInfo2 };
}