Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to convert character to string by java

Shulou Source: shulou.com Published: 2022-05-31 11:02:04 10月22日 Update

This article mainly introduces the relevant knowledge of java how to convert character into string, the content is detailed and easy to understand, the operation is simple and fast, and it has certain reference value. I believe you will gain something after reading this java article on how to convert character to string. Let's take a look.

Code:

/ / Standard numeric format string usage instructions and examples class NumberFormat {static void Main () {/ / {index [, alignment] [: format]} / / index-A zero-based integer indicating the element to be formatted in the object list. / / alignment-an optional integer indicating the minimum width, with blanks to fill in the deficiency. A negative number indicates left alignment and a positive number indicates right alignment. / / format-format string. The standard numeric format string takes the form of "Axx" An is a single letter and is described as follows: / / c-currency, xx indicates decimal places / / d-decimal, xx indicates significant places, insufficient zero filling, can only be used for integer / / x-hexadecimal, usage is the same as d / / e-index, xx indicates decimal places / / f-fixed point Xx indicates decimal places / / n-digits, outputs thousand-digit separators, others are the same as f / / g-regular, xx indicates the number of significant digits, using / / p-percentage, the shorter of e or f Xx indicates the number of decimal places / / for example, the output of the following statement is: "| ¥- 5.00 |-05 |-05 |-5.0 |-500% | 12345.7 | 12345.7 |" System.Console.WriteLine ("| {00:d2} c} | {0:d2} | {0magentin 50:d2} | {0:p0} | {1:f1} | {1:n1} |",-5, 12345.67)) }}

12345.ToString ("n"); / / generate 12345.00

12345.ToString ("C"); / / generate ¥12345.00

12345.ToString ("e"); / / generate 1.234500e+004

12345.ToString ("f4"); / / generate 12345.0000

12345.ToString ("x"); / / generate 3039 (hexadecimal)

12345.ToString ("p"); / / generate 1234500.00%

Percentage conversion to numerical type

Convert.ToDouble (s.TrimEnd ('%')) / 100

This is the end of the article on "how java converts characters to strings". Thank you for reading! I believe you all have a certain understanding of "how to convert characters into strings in java". If you want to learn more, you are welcome to follow the industry information channel.

Tags: Characters instructions strings digits generation character type decimal format numbers integers knowledge valid content standard percentage article output minimum code value Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi NVidia Shulou Tech Info Microsoft Docker