C# Convert ToBoolean(Decimal)
Description
Convert ToBoolean(Decimal)
converts the value of the
specified decimal number to an equivalent Boolean value.
Syntax
Convert.ToBoolean(Decimal)
has the following syntax.
public static bool ToBoolean(
decimal value
)
Parameters
Convert.ToBoolean(Decimal)
has the following parameters.
value
- The number to convert.
Returns
Convert.ToBoolean(Decimal)
method returns true if value is not zero; otherwise, false.
Example
The following example converts an array of Decimal values to Boolean values.
//from w ww .j a va 2 s .c o m
using System;
public class MainClass{
public static void Main(String[] argv){
decimal[] numbers = { Decimal.MinValue, -1234.56m, -100m, 0m,
300m, 6.45m, Decimal.MaxValue };
bool result;
foreach (decimal number in numbers)
{
result = Convert.ToBoolean(number);
Console.WriteLine("{0,-30} --> {1}", number, result);
}
}
}
The code above generates the following result.