Copied to clipboard

Flag this post as spam?

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


  • syn-rg 282 posts 425 karma points
    Mar 23, 2010 @ 07:25
    syn-rg
    0

    Display umbracoBytes as MB instead of KB

    Is there anyway to diplay the umbracoBytes value as MB instead of KB?

  • Stephan Lonntorp 195 posts 212 karma points
    Mar 23, 2010 @ 07:43
    Stephan Lonntorp
    1

    Just divide it by 1024, and round to the number of decimals you need.

  • bob baty-barr 1180 posts 1294 karma points MVP
    Mar 23, 2010 @ 20:49
    bob baty-barr
    2

    here is a script i use...

    <a href="{$docFile}" title="{$docName}" target="_blank"><xsl:value-of select="$docName"/></a>&nbsp;[ File Size: <xsl:value-of select="format-number(data[@alias='umbracoBytes'] div 1024,'#,###')"/>]

  • Christian Palm 278 posts 273 karma points
    Mar 23, 2010 @ 22:29
    Christian Palm
    3

    Here is the xslt extension helper we are using to print out the bytes nicely, in GB, MB, KB or bytes depending on the size

    public static string GetReadableFileSizeViaBytes(long Bytes)
    {
    if (Bytes >= 1073741824)
    {
    Decimal size = Decimal.Divide(Bytes, 1073741824);
    return String.Format("{0:##.##} GB", size);
    }
    else if (Bytes >= 1048576)
    {
    Decimal size = Decimal.Divide(Bytes, 1048576);
    return String.Format("{0:##.#} MB", size);
    }
    else if (Bytes >= 1024)
    {
    Decimal size = Decimal.Divide(Bytes, 1024);
    return String.Format("{0:##} KB", size);
    }
    else if (Bytes > 0 & Bytes < 1024)
    {
    Decimal size = Bytes;
    return String.Format("{0:##.##} Bytes", size);
    }
    else
    {
    return "0 Bytes";
    }
    }
  • Laurence Gillian 600 posts 1219 karma points
    May 04, 2010 @ 16:17
    Laurence Gillian
    4

    This is the above as XSLT ;) Laurie

    <xsl:variable name="size" select="data [@alias = 'umbracoBytes']" />
    <xsl:variable name="sizeAndSuffix">
        <xsl:choose>
            <xsl:when test="$size &gt;= 1073741824">
                <xsl:value-of select="format-number($size div 1073741824,'#,###')"/>
                <xsl:text>GB</xsl:text>
            </xsl:when>
            <xsl:when test="$size &gt;= 1048576">
                <xsl:value-of select="format-number($size div 1048576,'#,###')"/>
                <xsl:text>MB</xsl:text>
            </xsl:when>
            <xsl:when test="$size &gt;= 1024">
                <xsl:value-of select="format-number($size div 1024,'#,###')"/>
                <xsl:text>KB</xsl:text>
            </xsl:when>
            <xsl:when test="$size &gt; 0 and $size &lt; 1024">
                <xsl:value-of select="format-number($size div 0,'#,###')"/>
                <xsl:text> Bytes</xsl:text>
            </xsl:when>
            <xsl:otherwise>
                <xsl:text>0 Bytes</xsl:text>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:variable>
  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies