Byte to string in a specific format

Source: Internet
Author: User

I recently encountered some format conversion problems during encryption and decryption. I pasted the msdn example. For details:

Http://msdn.microsoft.com/zh-cn/library/y11056e9 (V = vs.100). aspx

There are other related information. Mark it and forget it later:

Http://msdn.microsoft.com/zh-cn/library/0c899ak8.aspx

Http://msdn.microsoft.com/zh-cn/library/dwhawy9k (V = vs.80). aspx

String [] formats = {"C3", "D4", "E1", "E2", "f1", "g", "N1 ",
"P0", "X4", "0000.0000 "};
Byte number = 240;
Foreach (string format in formats)

{

Console. writeline ("'{0}' format specifier: {1}", format, number. tostring (Format ));

}

Console output:

// 'c3' format specifier: $240.000
// 'd4 'format specifier: 0240
// 'e1 'format specifier: 2.4e + 002
// 'E2' format specifier: 2.40e + 002
// 'f1' format specifier: 240.0
// 'G' format specifier: 240
// 'n1 'format specifier: 240.0
// 'p0 'format specifier: 24,000%
// 'x4 'format specifier: 00f0
// '2017. 0000 'format specifier: 0240.0000

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.