Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Palle Hansen 143 posts 396 karma points
    Feb 28, 2014 @ 16:36
    Palle Hansen
    0

    Compare decimal numbers

    Hi.

    I'm a bit stuck in my coding.
    I have a rating system, and I need to show x numbers of stars depending of total score.

    I have the total score but when I try to show starts noting is show if the total scores is a decimal number.

    I have this on top:
    <xsl:decimal-format name="euro" decimal-separator="," grouping-separator="."/>
    and the is the total score variable:
    <xsl:variable name="ScoreValue" select="format-number($TotalSingleScore div $SuperTotal *10,'#.###,##','euro')"/>

    and here is the thing I try to do:

    <xsl:if test="$ScoreValue &gt;= 7.34 and $ScoreValue &lt;= 9.99">
    <img src="/img/greenstar.png" class="ratestar"/>
    <img src="/img/greenstar.png" class="ratestar"/>
    <img src="/img/greenstar.png" class="ratestar"/>
    <img src="/img/greenstar.png" class="ratestar"/>
    </xsl:if>

    No stars is shown if $ScoreValue output is 5,6 only if the $ScoreValue is like 5 or 6 ...

    Can anyone help me out here.

    /Palle

     

  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 8x admin c-trib
    Feb 28, 2014 @ 18:35
    Chriztian Steinmeier
    0

    Hi Palle,

    The format-number() function returns a formatted string, which you shouldn't use in comparisons (you're comparing a string with a number). You should only use it to display the value(s).

    Try something like this instead:

    <xsl:variable name="ScoreValue" select="$TotalSingleScore div $SuperTotal * 10" />
    <xsl:variable name="ScoreValueFormatted" select="format-number($ScoreValue, '#.###,##', 'euro')" />
    

    /Chriztian

  • Palle Hansen 143 posts 396 karma points
    Mar 01, 2014 @ 09:00
    Palle Hansen
    0

    Hi Chriztian.

    It works :)

    Thanks for your reply.

     

Please Sign in or register to post replies

Write your reply to:

Draft