程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

python formatted output retains 3 decimal places (java rounds up and down)

編輯:Python

Hello everyone, meet again, I'm your friend Quanstack Jun.

What this post wants to achieve:

It will configure entity service rules (if it can be implemented by entity service rules, try to use entity service rules to implement),

The field that sets the entity service rule must trigger the condition,

The decimal type can realize the functions of rounding down, rounding up, and rounding up.

Look at the interface test effect first:

Decimal 1.0 round down 1.0, round up 1.0, round up 1.0

Decimal 1.1 is rounded down to 1.0, rounded up to 1.0, rounded up to 2.0

Decimal 1.5 rounded down to 1.0, rounded up to 2.0, rounded up to 2.0

Decimal 1.99 rounded down to 1.0, rounded up to 2.0, rounded up to 2.0

Specific settings:

Add 4 decimal fields, namely "decimal", "decimal_round down", "decimal_round up", "decimal_round up".

Add entity service rules in the document header:

Entity service rules, the decimal field changes, triggering the corresponding 3 fields to fetch

(If it is implemented in the value update method, you need to configure the 3 value update services of the decimal field,

And if multiple fields are involved, each field needs to be updated with a configuration value,

If configuring entity service rules, clear and clear),

Precondition: Decimal field change condition Decimal=Decimal field must trigger condition

Some people here often ask about setting 1=1, so the setting will not be executed,

Because whether the entity service rule needs to be executed, it is necessary to judge whether the value of a field has changed, and whether the corresponding field identifier is set in the precondition of the entity service rule,

If it is inside, the precondition for parsing and judgment will be performed. Obviously, setting 1=1 is an identifier that does not contain any fields, which is equivalent to a useless entity service rule configuration.

Specific three calculation formula settings:

F_PAIK_Decimal1 = int ( F_PAIK_Decimal )

ie decimal_round down = int (decimal) int round down

F_PAIK_Decimal2 = round ( F_PAIK_Decimal )

ie decimal_rounding = round (decimal) round rounding

F_PAIK_Decimal3 = int ( round ( F_PAIK_Decimal + 0.49 ) )

ie decimal_round up = int ( round ( decimal + 0.49 ) )

Note here: Python supports math.ceil (decimal value), but we can't use it directly here,

Because we need to import the import math module, we cannot use it here.

So we work around it, because rounding down and rounding can be used directly,

Round up is achieved by a workaround of rounding and rounding down.

End Thank you.


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved