Support General Using Field Values in Calculations - 2 questions

• Creator
Topic
• #12231

Hi Anh - I'm using MB to create custom fields for a CPT 'Pacakges'. The fields collect data that is then used to create a 'Package' so potential buyers can review a given restaurant that is for sale.

Aside from the standard form fields included with MB AIO, I also need -

Percentages (80%, 16%, etc)

Question #1 - how can I implement fields that recognize numerical input as a percentage? I am using the number field now....

I also need to create calculations based on field values (100 x 6% = 6). In addition to the data entry fields, I also need to display a few simple calculations to present financial data.

Question #2 - how do I perform calculations and then display the result?

thanks!

Viewing 4 replies - 1 through 4 (of 4 total)
• Author
Replies
• #12267
#12286

Hi Neil,

Question #1 – how can I implement fields that recognize numerical input as a percentage? I am using the number field now….

It actually doesn't. You need to write some description to the field to let users know it's a percentage.

Question #2 – how do I perform calculations and then display the result?

When you insert the code to the front end, please add some calculation before that:

``````\$value = rwmb_meta( 'percentage' );
\$value = \$value / 100 * \$another_field_value;
echo \$value;``````

If you're using a page builder like Beaver Builder, I'd suggest writing a custom shortcode to put into a text module in BB. The shortcode might be like this (put in `functions.php`):

``````add_shortcode( 'your_percentage', function( \$atts, \$content ) {
\$value = rwmb_meta( 'percentage' );
\$value = \$value / 100 * \$another_field_value;
return \$value;
} );``````

In a text module in BB, simply insert `[your_percentage]` and your result will appear.

#12306
#27762

Hi Anh,
Could you explain how to do the same into a MB View please ?