Another (hopefully) basic operation here that is flumexing me thus far!
I have an estate agent website and I am using Numeric as the property values, my issue is with formatting the value to include a , after the first 3 digits e.g. £500,000.
Any ideas on how I can format the numeric figures please guys in the code below:
An example of how you could do it is by using this:
@{ if (CurrentPage.HasValue("capitalValue")){ var price = CurrentPage.capitalValue.ToString(); <li>Capital Value: <span class="thin">£@price.Substring(0,3),@price.Substring(3,3)</span></li> } }
And this can be place directly into your template, but you could also create a partial view or a partial view macro. In this example I just check if the field on the current page has a value, if so, then I make to subtrings, the first one, takes the first 3 digits, and the last takes the last 3 digits. And to make this solution more robust, you could add a regular expression on the field where the user should type in the price.
I have made a regular expression where it only allows 0-6 characters, the regular expression look like this:
Formatting Numeric Datatype as currency
Hi all,
Another (hopefully) basic operation here that is flumexing me thus far!
I have an estate agent website and I am using Numeric as the property values, my issue is with formatting the value to include a , after the first 3 digits e.g. £500,000.
Any ideas on how I can format the numeric figures please guys in the code below:
<li>Capital Value: <span class="thin">£@Umbraco.Field("capitalValue")</span></li>
Please note that this is going straight into the template as opposed to Partial Macro or XSLT.
Hi Brian,
An example of how you could do it is by using this:
And this can be place directly into your template, but you could also create a partial view or a partial view macro. In this example I just check if the field on the current page has a value, if so, then I make to subtrings, the first one, takes the first 3 digits, and the last takes the last 3 digits. And to make this solution more robust, you could add a regular expression on the field where the user should type in the price.
I have made a regular expression where it only allows 0-6 characters, the regular expression look like this:
Hope this could be a solution for you.
/Dennis
Couldn't you just leverage string.format?
http://stackoverflow.com/questions/105770/net-string-format-to-add-commas-in-thousands-place-for-a-number
Hi Brian,
Based on the post Mike has linked to I have developed a simpler solution than the first one I made.
Hope this helps,
/Dennis
That's great, thanks guys.
Mike, good to see you around chap, long time!! you should email me sometime [email protected]..
Using Dennis method
Hi
Surprisingly, this works
Regards
Gary
is working on a reply...