- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Convert Decimal to equivalent 8-bit unsigned integer in C#
To convert the value of the specified Decimal to the equivalent 8-bit unsigned integer, the code is as follows −
Example
using System; public class Demo { public static void Main(){ Decimal val1 = 6.59m; Decimal val2 = 30.12m; Decimal val3 = 69.34m; Console.WriteLine("Decimal 1 = "+val1); Console.WriteLine("Decimal 2 = "+val2); Console.WriteLine("Decimal 3 = "+val3); byte res1 = Decimal.ToByte(val1); byte res2 = Decimal.ToByte(val2); byte res3 = Decimal.ToByte(val3); Console.WriteLine("Byte value1 (Decimal to Byte) = "+res1); Console.WriteLine("Byte value2 (Decimal to Byte) = "+res2); Console.WriteLine("Byte value3 (Decimal to Byte) = "+res3); } }
Output
This will produce the following output −
Decimal 1 = 6.59 Decimal 2 = 30.12 Decimal 3 = 69.34 Byte value1 (Decimal to Byte) = 6 Byte value2 (Decimal to Byte) = 30 Byte value3 (Decimal to Byte) = 69
Example
Let us now see another example −
using System; public class Demo { public static void Main(){ Decimal val1 = -0.22m; Decimal val2 = -0.01m; Console.WriteLine("Decimal 1 = "+val1); Console.WriteLine("Decimal 2 = "+val2); byte res1 = Decimal.ToByte(val1); byte res2 = Decimal.ToByte(val2); Console.WriteLine("Byte value1 (Decimal to Byte) = "+res1); Console.WriteLine("Byte value2 (Decimal to Byte) = "+res2); } }
Output
This will produce the following output −
Decimal 1 = -0.22 Decimal 2 = -0.01 Byte value1 (Decimal to Byte) = 0 Byte value2 (Decimal to Byte) = 0
- Related Articles
- Convert Decimal to the equivalent 64-bit unsigned integer in C#
- Convert the value of the specified Decimal to the equivalent 16-bit unsigned integer in C#
- ConvertDecimal to equivalent 32-bit unsigned integer in C#
- Implicit conversion from 16-bit unsigned integer (ushort) to Decimal in C#
- Implicit conversion from 32-bit unsigned integer (UInt) to Decimal in C#
- Implicit conversion from 8-bit signed integer (SByte) to Decimal in C#
- Convert varchar to unsigned integer in MySQL
- Converting an unsigned 32 bit decimal to corresponding ipv4 address in JavaScript
- Implicit conversion from 64-bit signed integer (long) to Decimal in C#
- Convert decimal integer to octal in Java
- Convert decimal integer to hexadecimal number in Java
- Restoring Division Algorithm For Unsigned Integer in C++
- Java Program to convert decimal integer to octal number
- Java Program to convert decimal integer to hexadecimal number
- How to convert array of decimal strings to array of integer strings without decimal in JavaScript

Advertisements