How to auto-convert a whole number into it's 2 decimals points?

限于喜欢 提交于 2019-12-24 06:47:09

问题


Following the previous answers How to make a condition based on the number of decimals a number has with the IFS and AND functions in Google Sheets?

The formula given didn't return a result for whole numbers (any number without decimals, for example: 1(.00), 12(.00) etc.).

To make it return a result also for inputs with whole numbers, I thought of some formula like this:

=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).

How to make this formula

=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, )))

valid for whole numbers as well?

So that it returns a result for the whole number as well?


回答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, )))



来源:https://stackoverflow.com/questions/56288852/how-to-auto-convert-a-whole-number-into-its-2-decimals-points

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!