Prices in Shopify are integers in the currency's smallest unit (cents). of 3499 is $34.99. The threshold for free shipping at $40 is 4000.
How much more is needed is a subtraction. The fill percentage is a division, with a catch.
{% assign threshold = 4000 %}
{% assign remaining = threshold | minus: cart.total_price %}
{% assign pct = cart.total_price | times: 100 | divided_by: threshold %}
{# times: 100 FIRST, or Liquid's integer division floors pct to 0 #}
cart.total_price | divided_by: 4000 is 0 for any cart under $40, integer division. Multiply by 100 before dividing. This is the bug AI ships here.