0
votes

I'm trying to display a numeric value of 0.733675715 using liquid templates.

Following code

{%- assign rate = 0.733675715 -%}
{{ rate }}

Results in: 0.7336757

I could not find a way to:

  1. convert numeric value to string
  2. force liquid to display all decimal places

--edit

Note: DotLiquid is used by Azure logic apps integration accounts to do transformations between JSON/XML/Text

1
Hi Karpik, where are you executing this Liquid? Is it in Shopify, on a Jekyll site, or somewhere else? When I render the same template my number isn't truncated — I get 0.733675715. - Adam Hollett
Hey, thanks for commenting! I've tried this: dotliquidmarkup.org/try-online But what I'm really using is Azure Logic Apps LIQUID transforms - and that gives me the same result - truncated result :/ - Karpik
I confirmed with docs.microsoft.com/en-us/azure/logic-apps/… that the problem may actually be with github.com/dotliquid/dotliquid - Karpik
Yeah, that might be the issue — I'm not seeing the same result with Ruby Liquid. Hope you can find a solution! - Adam Hollett

1 Answers

1
votes

I found the issue in dotLiquid library. The fix can be found in this PR: https://github.com/dotliquid/dotliquid/pull/353.

Basically, in the assign statement, dotliquid is parsing the value as float[1], hence the lost precision.

// Floats.
match = FloatRegex.Match(key);
if (match.Success)
{
    // For cultures with "," as the decimal separator, allow
    // both "," and "." to be used as the separator.
    // First try to parse using current culture.
    if (float.TryParse(match.Groups[1].Value, NumberStyles.Number, FormatProvider, out float result))
        return result;

    // If that fails, try to parse using invariant culture.
    return float.Parse(match.Groups[1].Value, CultureInfo.InvariantCulture);
}
  1. https://github.com/dotliquid/dotliquid/blob/b415f6aaa5b66fdbfa9c5d676427c7663c1e98e3/src/DotLiquid/Context.cs#L347