This is a creation in Article, where the information may have evolved or changed.
Four homes six into 50% pairs is a more accurate and scientific method of counting retention, which is a kind of digital revision rule, aka Banker rounding method. It is more accurate than the usual rounding method.
Specific rules:
The number to be repaired is less than 5 o'clock, and the number is shed;
If the number of the repaired is greater than 5 o'clock, the rounding is taken;
The number of the repair is equal to 5 o'clock, to see the number of the front 5, if the odd is carry, if even the number will be 5 off, that is, after the end of the revision of the figure is an even number, if there is no "0" in the back of any numbers, then regardless of whether the front of the 5 is an odd or even,
Mnemonic formula:
four six into five consideration, five after non-zero into one, five after the zero look at the odd even, five ago for I should give up, five ago for odd to go into a
Golang in floating-point type by default using the Banker rounding method, such as the following using code validation example
import ("fmt")func main() {fmt.Printf("9.8249=>%0.2f(四舍)\n", 9.8249)fmt.Printf("9.82671=>%0.2f(六入)\n", 9.82671)fmt.Printf("9.8351=>%0.2f(五后非零就进一)\n", 9.8351)fmt.Printf("9.82501=>%0.2f(五后非零就进一)\n", 9.82501)fmt.Printf("9.8250=>%0.2f(五后为零看奇偶,五前为偶应舍去)\n", 9.8250)fmt.Printf("9.8350=>%0.2f(五后为零看奇偶,五前为奇要进一)\n", 9.8350)}
Output results
9.8249 => 9.82(四舍) 9.82671 => 9.83(六入) 9.8351 => 9.84(五后非零就进一) 9.82501 => 9.83(五后非零就进一) 9.8250 => 9.82(五后为零看奇偶,五前为偶应舍去) 9.8350 => 9.84(五后为零看奇偶,五前为奇要进一)
Therefore, it is convenient for me to use the FMT method to make the banker trade-offs of floating-point types and obtain their approximate numbers. For example:
import ("fmt""strconv")func main() {s := fmt.Sprintf("%0.6f", 17.82671567890123456789987654324567898765432)f, _ := strconv.ParseFloat(s, 64)fmt.Println(s, f)}
Output results
17.826716 17.826716