How to create a custom number format?

Good day to all!
Is it possible (for Calc) to create a number format like this: “0000 0000” ?
For example, the binary number 00001010 is formatted as 0000 1010.

Version: 7.4.1.2 (x64) / LibreOffice Community
Build ID: 3c58a8f3a960df8bc8fd77b461821e42c061c5f0
CPU threads: 4; OS: Windows 10.0 Build 19044; UI render: Skia/Raster; VCL: win
Locale: ru-RU (ru_RU); UI: en-US
Calc: threaded

First of all - you can’t have a binary number format in Calc. So whatever number you enter, it will not be shown as binary.

Then, you definitely can use a code like 0000" "0000 to show decimal numbers with a literal insert in the middle. But then, your “0000 1010” would be number “one thousand ten”, not “ten” which it would be if it were a binary number.

I would suggest you to not try to fake binary numbers using decimals having similar visual representation: their arithmetic operations would be “wrong”. And if you don’t intend to use them in calculations, then just use strings, like what functions like DEC2BIN return. Then you may apply a post-processing to that string, like

REPLACE(DEC2BIN(10;8);5;0;" ")
3 Likes

No easy way to smoothly display a cell value “inline” in binary format. Spreadsheet user interface is geared at “mostly decimal”, so to work in binary and have the values available for calculations, you need to explicitly convert between number bases. Values converted to binary will always exist as text strings. Functions BASE(), BIN2DEC(), DEC2BIN(), TEXT() and VALUE() may be relevant. I believe the BIN2DEC and DEC2BIN functions work on “10 bit signed”, so they handle values between (decimal) -512 to +511.

If you can explain your situation in more detail, you may receive more specific advice. What is your workflow?

  • How are the numbers input?
  • How do you manipulate values (e.g. logical or arithmetic operations)?
  • What is the “purpose” or “target audience” (quick “data conversion” tool for your own use, visualizing binary operations for your students, etc.)?
1 Like

Hi! The task is simple. The result of the DEC2BIN() function needs to be formatted to make it easier to read a binary number. The representation in the form of two groups of four digits is convenient to observe. This is for viewing purposes only, no further calculations are required.

In general, it is possible to format it this way (mikekaganski).
Although, I was counting on some format (template, mask, etc.) to entrust this to Calc.
Thanks to you and everyone who took part!

What I can offer isn’t related to the NumberFormat feature at all. It’s about the conversion of the ordinary internal representation of numbers which not is decimal but follows the standard IEEE 754 Double.
But probably this also is of interest for the questioner or other visitors.
Actual NFs for dyadic, hex, … would surely be nice. The related development seems to be absorbed by locale-related features and funny coloring…
I also have an open enhancement bug concerning specialized fraction formats. But there are real lots of possible wishes only relevant for a very small subset of users.
Might there once be a NF option expressed for the code line by [applyudf] followed by a url e.g?
conversionOfNumbesrToDyadicRepresentations.ods (14.3 KB)

1 Like