如何将整数自动转换为2个小数点?

时间:2019-05-24 08:39:34

标签: regex if-statement google-sheets array-formulas google-sheets-formula

按照先前的答案 How to make a condition based on the number of decimals a number has with the IFS and AND functions in Google Sheets?

给出的公式未返回整数(任何不带小数的数字,例如:1(.00),12(.00)等)的结果。

要使其也返回带有整数的输入的结果, 我想到了这样的公式:

=IF(A1=(a whole number/number without decimals),A1.00(A1 formatted as a whole number with two decimals),A1(A1 with any number of decimals>2 decimals).

如何制作此公式

=ARRAYFORMULA(
 IF((LEN(IFERROR(REGEXEXTRACT(TO_TEXT(A1:A), "\.(.*)")))=4) * 
    (A1:A>B1:B) * (C1:C="Good"),     (A1:A-B1:B)*10000,
 IF((LEN(IFERROR(REGEXEXTRACT(TO_TEXT(A1:A), "\.(.*)")))=2) * 
    (A1:A>B1:B) * (C1:C="Great"),    (A1:A-B1:B)*100, )))

对整数也有效吗?

以便它也返回整数的结果?

1 个答案:

答案 0 :(得分:1)

=ARRAYFORMULA(
 IF((LEN(IFERROR(REGEXEXTRACT(TO_TEXT(A1:A), "\.(.*)")))=4) * 
    (A1:A>B1:B) * (C1:C="Good"),     (A1:A-B1:B)*10000,
 IF((LEN(IFERROR(REGEXEXTRACT(TO_TEXT(TEXT(A1:A, "00.00")), "\.(.*)")))=2) * 
    (A1:A>B1:B) * (C1:C="Great"),    (A1:A-B1:B)*100, )))

0