Formula to return a number with a certain amount of decimals

RonOliver

Board Regular
Joined
Aug 30, 2022
Messages
82
Office Version
  1. 365
Platform
  1. Windows
Hi!

299
9.00
9


So A1 is the number of decimals to be displayed. B1 is the number that I want displayed with decimals. Now, my problem is the ROUND function will get rid of the decimals if they are not necessary, the TEXT/CHOOSE functions will do what I want them to do but they will give me the number as a text (and thus, it is impossible for me to work with it further in other mathematical operations), and the VALUE/TEXT/CHOOSE functions will just do what the ROUND function did in the first place.

My question: is there a way for me to display the number in B1 with the amount of decimals specified in A1 even if decimals are not necessary? I want the amount of decimals to be dependent on A1, so if the value changes, the amount of decimals will change too. Can't use VBA, sorry.

Thank you very much!
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
... the TEXT/CHOOSE functions will do what I want them to do but they will give me the number as a text (and thus, it is impossible for me to work with it further in other mathematical operations)...
It is possible to use numbers-as-text in mathematical operations: e.g., ="9.00"+2 evaluates to 11. So, see if the following formula works for you:
Excel Formula:
=TEXT(B1,"0"&IF(A1>0,"."&REPT(0,A1),""))
 
Last edited:
Upvote 1
Solution
Turns out that actually works. My mistake was also trying to use SUM or AVERAGE with texts (which still doesn't work for me as it is, but it does once I use the VALUE function when performing a mathematical operation). Thanks very much!
 
Upvote 0
Turns out that actually works. My mistake was also trying to use SUM or AVERAGE with texts (which still doesn't work for me as it is, but it does once I use the VALUE function when performing a mathematical operation). Thanks very much!
Thanks RonOliver. It works. However it is possible to do the same without transforming them onto Text, keeping them as Numbers?. Thanks
 
Last edited:
Upvote 0
it is possible to do the same without transforming them onto Text
As long as there's a sensible maximum for the number of decimal places you want to display, one option could be to use a series of conditional formatting rules.
Book1
ABC
1199.0
Sheet1
Cell Formulas
RangeFormula
C1C1=B1
Cells with Conditional Formatting
CellConditionCell FormatStop If True
C1Expression=$A1=5textNO
C1Expression=$A1=4textNO
C1Expression=$A1=3textNO
C1Expression=$A1=2textNO
C1Expression=$A1=1textNO
C1Expression=$A1=0textNO
 
Upvote 0
As long as there's a sensible maximum for the number of decimal places you want to display, one option could be to use a series of conditional formatting rules.
Book1
ABC
1199.0
Sheet1
Cell Formulas
RangeFormula
C1C1=B1
Cells with Conditional Formatting
CellConditionCell FormatStop If True
C1Expression=$A1=5textNO
C1Expression=$A1=4textNO
C1Expression=$A1=3textNO
C1Expression=$A1=2textNO
C1Expression=$A1=1textNO
C1Expression=$A1=0textNO
Thanks FormR. I´m sorry but I havent´cach you
 
Upvote 0
You can use conditional formatting rules to check the value of the cell that tells you how many decimal places you want to be displayed and have the condition format display that number.

You would need a rule to check for a 0 and display 0 decimal places, and another to check for a 1 and display 1, and another for 2 etc etc.
 
Upvote 0
You can use conditional formatting rules to check the value of the cell that tells you how many decimal places you want to be displayed and have the condition format display that number.

You would need a rule to check for a 0 and display 0 decimal places, and another to check for a 1 and display 1, and another for 2 etc etc.
 
Upvote 0
I think something has gone wrong with your reply in post#9 as I can't see anything other than the quote.
 
Upvote 0

Forum statistics

Threads
1,214,915
Messages
6,122,217
Members
449,074
Latest member
cancansova

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top