C # Complete Manual (01)

xiaoxiao2021-03-06  92

3.5 Decimal type

Decimal types are usually used in currency calculations. The Decimal type uses 128 points to represent the values ​​between 1e-28 to 7.9e 28.

Normal floating point calculations often encounter a lot of rounding errors when they are applied to a decimal.

"In Java, the main design objectives of Float and Double types are for scientific computing and engineering calculations. They perform binary floating point placement, which is designed to provide more accurate fast approximate calculations on wide-area numerical range. However They do not provide full and accurate results, so they should not be used to request precise results. The FLOAT and Double type are especially suitable for currency calculations, because let a float or double exactly expressed 0.1 (or any other negative number of 10) The secondary value) is impossible. "[EffectiveJava Chinese, 127]

Compared with Java, C # provides an accurate calculated Decimal type, while Java provides a BigDecimal type, but this type is inconvenient than using the original calculation type. In addition, use int or long while handling the decimal point.

When assigning the Decimal type, the decimal must have suffix m, such as:

Decimal price = 19.95m;

3.8 Some Output Options

Format the output digital data.

WriteLine ("Format String", Arg0, Arg1, ..., Argn);

The format specifex is in the following basic forms:

{Argnum, Width: fmt}

Among them, argnum specifies the number of variable elements to display (starting from 0). WIDTH specifies the minimum width of the field, and the FMT specifies the format.

5.2 Switch statement

The expression of Switch must be an integer type, such as Char, Byte, Short, and Int, or String type.

In C #, it will be incorrect with a CASE-related statement sequence after another CASE, which is called "not penetrating" rules. This is why the Case sequence ends with the Break statement. In the Switch statement, you can use the GOTO jump statement.

[C # Complete Manual] C # Complete Manual Zhu De Shuang Hu Fengyan Hu Fu Ming and other translations. The original name: The Complete Reference C # [Beauty] Herbert Schildt

[EffectiveJava Chinese]

转载请注明原文地址:https://www.9cbs.com/read-123383.html

New Post(0)