fraction formatting

Galgenstrick

New Member
Joined
Apr 21, 2012
Messages
43
This is a slightly weird questions, but I need a decimal converted to a fraction a certain way, similar to the fractional number formatting. I'm guessing this will have to be done in VBA

Here's an example of what I'm looking to do:

I have a cell that is always rounded to the nearest 0.5, I want to convert that to a fraction of either 1/16" if the number is whole, or 1/32" if the number ends in 0.5.

Example:
0.5 converted to 1/32"
1 converted to 1/16"
3 converted to 3/16"
3.5 converted to 7/32"
-5 converted to -5/16"
-5.5 converted to -11/32"
etc...
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
You could do it with a formula.

=IF(INT(A1)=A1,A1&"/16""", A1/0.5&"/32""")
 
Upvote 0
This formula assumes the lookup value is in A1. The output will be a text value, not a numerical value!

=If(roundup(A1,0)=A1,A1&”/16”,A1*2&”/32”)
 
Upvote 0
How about just ...

[Table="width:, class:grid"][tr][td="bgcolor:#C0C0C0"][/td][td="bgcolor:#C0C0C0"]
A​
[/td][td="bgcolor:#C0C0C0"]
B​
[/td][td="bgcolor:#C0C0C0"]
C​
[/td][/tr][tr][td="bgcolor:#C0C0C0"]
1​
[/td][td]
0.5​
[/td][td="bgcolor:#CCFFCC"]
1/32​
[/td][td]B1: =A1/16[/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
2​
[/td][td]
1​
[/td][td="bgcolor:#CCFFCC"]
1/16​
[/td][td]Format of B1: # ??/??[/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
3​
[/td][td]
3​
[/td][td="bgcolor:#CCFFCC"]
3/16​
[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
4​
[/td][td]
3.5​
[/td][td="bgcolor:#CCFFCC"]
7/32​
[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
5​
[/td][td]
-5​
[/td][td="bgcolor:#CCFFCC"]
- 5/16​
[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
6​
[/td][td]
-5.5​
[/td][td="bgcolor:#CCFFCC"]
- 11/32​
[/td][td][/td][/tr]
[/table]
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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