0
votes

We are using Umbraco 7.5.x on Umbraco Cloud. we have a custom document type with a Umbraco.Decimal datatype.

The correct values are being stored as we can edit them from the backoffice. But when we try to display those values, only values above zero are show properly. Negative values (eg -0.75) are not displayed.

What is the correct way to display the values of this datatype so all values are shown?

Our use case above is, we have a nodes that display values of stock prices, which can be negative sometimes. the values are stored in a Umbraco.decimal field. The positive values display without any issues. Any negative values display as zero.

For example in our view, we grab the a particular node, and display its value from the fields:

@{
var lastStockValues = Umbraco.Content(123).Children.Last();
}    
<div>@((lastStockValues.stockdelta*100).ToString("0.##")) % </div>

Thanks!

1
Please post the code you have tried so far. What do you expect that code to do and what is it actually doing?BPS
Thanks, I've updated the info. Hope this helps!Stan

1 Answers

0
votes

I strongly recommend using typed models rather than dynamic ones. This way you can be sure your types are correct:

@{
    var lastStockValuesNode = Umbraco.TypedContent(123).Children().Last();
}
<div>@((lastStockValuesNode.GetPropertyValue<decimal>("stockdelta") * 100).ToString("0.##"))</div>

In this case, lastStockValuesNode is of type IPublishedContent which represents a page/node in Umbraco.

You can then use the method .GetPropertyValue<type>(alias). In this case, we are casting to type decimal.

This may solve your issue if the dynamic typing is converting the decimal to the wrong type.

Documentation: https://our.umbraco.org/documentation/reference/querying/UmbracoHelper/#typedcontent-int-id