Wundermatics
Human friendly WordPress Automation
Calculated Fields for ACF supports formatting the formula output using a format string. The format string is passed to the PHP sprintf() function. So any format string that works with that function also works with this plugin. The format string is entered into the “Number format” in the field definition:
The PHP formatting string consists of five different segments (well, actually six but in the case of this plugin, only five of them matters), percent sign, flags, width, precision and type specifier put together like this:
%[flags][width][.precision]specifier
Percent sign %
The percent sign marks the beginning of a number format string, it always needs to be there to mark the beginning of a rule to format a number.
Flags (optional)
The flags are used to pad the resulting output if needed. It can tell you how to pad (left or right justify) and what character to use, usually zeros or spaces. The flags often only makes sense if you also use the width described below.
Width
The minimum width of the resulting outputted string. You can use this to force the output to always have the same string length.
Precision
The number of decimals to use when the type is a floating point number. You can use this to force a fixed number of decimals in the output.
Specifier
The specifier defies how to treat the number. Typically the most used values would be “d” for a normal integer and “F” for a floating point number.
Read the full details about the different parts and how to combine them in the PHP documentation.
Sometimes the easiest way to explain something is to use examples. Here are a few common format string that you may find useful:
It’s also possible to omit output if the formula returns zero (0). To do this, toggle the “Blank if zero” field to Yes.
Powered by BetterDocs
Your email address will not be published. Required fields are marked *
Comment
Yes, sign me up for informational and marketing emails from wundermatics.com
Name *
Email *
Website
Save my name, email, and website in this browser for the next time I comment.
Get the most out of Calculated Fields for ACF. Receive news about plugin updates, new plugins & add-ons, sales and discounts! First time subscribers receive a 15% discount coupon valid for any future purchase.
Email Address By checking this box I consent to the use of my information provided for email marketing purposes. Submit
By checking this box I consent to the use of my information provided for email marketing purposes.