VirtoCommerce / vc-storefront-deprecated

VirtoCommerce Storefront for ASP.NET (.NET Framework) repository (DEPRECATED)
http://virtocommerce.com
Other
26 stars 112 forks source link

Add ability to add zeroes after digits in fraction #35

Closed asvishnyakov closed 7 years ago

asvishnyakov commented 7 years ago

In gitter client says:

public class MathFilters
{
    public static object Round(object input, int digits = 0)
    {
        if (input != null)
        {
            input = Math.Round(Convert.ToDecimal(input, CultureInfo.InvariantCulture), digits);
        }
        return input;
    }

I modified this method because the Round method was always returning a value with only 1 number after the decimal Convert.ToDouble(input) was returning for example 100.1 and the Math.Round method was then never returning a 100.10 value is in the Liquid template I have round: 2 {{ value | round: 2 }}

Do not use this code, because you will loose a part of fraction. Instead, add options for round or create new tag.

tatarincev commented 7 years ago

Need to add new liquid filter format similar as is made there https://github.com/dotliquid/dotliquid/issues/111

asvishnyakov commented 7 years ago

Filter works as expected:

{% assign test = 11.22 %}
{{ test | format: '#0.000' }}
output: 11.220
{% assign test = 11.22 %}
{{ test | format: 'e3' }}
output: 1.122E+001

(syntax is the same as for Int32.ToString), but it's not applicable to prices, because they renders on client side through angular. Standard angular number filter with may be used instead to specify fraction size.