# NO BUG: Divide by function in Metabox Views created Critical Error when Editing Bricks

**URL:** <https://forum.bricksbuilder.io/t/no-bug-divide-by-function-in-metabox-views-created-critical-error-when-editing-bricks/22983>\
**Category:** Bugs\
**Tags:** v1-9-8\
**Created:** [May 24, 2024, 6:31am UTC](https://forum.bricksbuilder.io/t/no-bug-divide-by-function-in-metabox-views-created-critical-error-when-editing-bricks/22983 "2024-05-24T06:31:41Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![saint](https://forum.bricksbuilder.io/letter_avatar_proxy/v4/letter/s/73ab20/32.png) [@saint](https://forum.bricksbuilder.io/u/saint)\
**Post date:** [May 24, 2024, 6:31am UTC](https://forum.bricksbuilder.io/t/no-bug-divide-by-function-in-metabox-views-created-critical-error-when-editing-bricks/22983/1 "2024-05-24T06:31:41Z")

</div>

**Browser** : Chrome 110  
**OS** : Windows  
**Video** : [mbv-divide-by-crashes-bricks-editor](https://go.screenpal.com/watch/cZhZh4VLG8I)

Hi, I created a Metabox View and used Bricks to display the shortcode for that View in the Rich Text Editor.

But I’m running into a strange issue where the _frontend_ page with the Metabox View renders just fine. The output of the Metabox View is also correct.

However, when I use a Twig template statement with a divider in it, such as:

> {% set xxx\_pct = (xyz / abc \* 100) %}

or

> {{ xxx / yyy }}

The Bricks Editor on the _backend_ suddenly throws a **Critical Error** message.

If I remove the divide by math statement, the Bricks Editor on the backend reverts back normally and I can edit the template again.

I am confused at why the frontend would render the Metabox View with no issues, but the backend would throw a critical error and what I would need to do to fix this?

Thank you.

---

<div class="post-metadata">

**Author:** ![itchycode](https://forum.bricksbuilder.io/user_avatar/forum.bricksbuilder.io/itchycode/32/4542_2.png) [@itchycode](https://forum.bricksbuilder.io/u/itchycode)\
**Post date:** [May 29, 2024, 5:45am UTC](https://forum.bricksbuilder.io/t/no-bug-divide-by-function-in-metabox-views-created-critical-error-when-editing-bricks/22983/2 "2024-05-29T05:45:30Z")

</div>

Hi @saint ,

I think the template already set a populate content am I right?  
I suspect the `star_cnt_ttl` or `five_start_cnt` variable value in your video could be zero or undefine due to certain reason.

Can you write some logic to handle these possibility?

Alternatively, please turn on Error log and check what is the actual error.

Regards,  
Jenn

---

<div class="post-metadata">

**Author:** ![saint](https://forum.bricksbuilder.io/letter_avatar_proxy/v4/letter/s/73ab20/32.png) [@saint](https://forum.bricksbuilder.io/u/saint)\
**Post date:** [June 27, 2024, 11:28pm UTC](https://forum.bricksbuilder.io/t/no-bug-divide-by-function-in-metabox-views-created-critical-error-when-editing-bricks/22983/3 "2024-06-27T23:28:00Z")

</div>

Hi Jenn,

You are totally right. Turns out, it was the can’t “Divide by Zero” that was causing it. I’ve added in some additional logic to handle this, and it looks like it is working.

For those that may run into the same issue in the future, I wrapped it in an if statement to check if it is greater than zero first.

```auto
{% if ( five_star_cnt > 0 ) and ( star_cnt_ttl > 0 ) %}
	{{ five_star_cnt / star_cnt_ttl }}
{% endif %}

```

Bricks will throw a critical error in the backend when you go and edit it if there is a “Divide by Zero” issue, but the calculation will show up fine on the frontend, so something to check or be aware of when doing calcs.
