Developer forum

Forum » Development » Different results from formatting currencies with symbol

Different results from formatting currencies with symbol

Kristoffer Surrow
Kristoffer Surrow
Reply

Hi Dynamicweb

I'm trying to format prices in a Razor template, in DW version 9.14.9.

For this I'm using the CurrencyService from the "Dynamicweb.Ecommerce" - module, to format prices depending on the currency settings.

 

Based on the API documentation, there are 2 methods for formatting currencies:

currencyService.Format()

and currencyService.FormatCurrency()

 

When I'm using the currencyService.Format(), the price is formatted correctly, and the symbol is also placed correctly ("37.551,20 kr."), based on the pattern I've chosen within currency settings.

But the problem with this method is that it automatically rounds the prices, which is why I have to use the currencyService.FormatCurrency()-method instead

When I'm using currencyService.FormatCurrency(), the price is unfortunately formatted using the wrong pattern ("kr.37.551,20"), and I can't use this method either.

 

I think theres an issue with the "currencyService.FormatCurrency()"-method not formatting the price based on the pattern ("n $") selected within currency-settings, but instead uses the default pattern ("$n"), when formatting prices.

 

Attached is a note where I've copied the call of each method within a debug session


Replies

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply
This post has been marked as an answer

Can you show the setup of your currency?

I can see from your debug session that the currency have an "Ecommerce rounding" set on it ("Rounding1") which will add some rounding based on how that has been setup.

The other thing you need to be aware of that the currency formatting have 2 ways of working - one based on the "Regional info" setting where the settings in the "Regional settings" will be used. This is the 'new' way of formatting prices and is the recommended approach.
The other option is where you set "Regional info" to none, then it is the "Settings" that will be used - then you have to add a space after the specified in the field "currency symbol" - so it is not "Kr." but "Kr. " with the additional space.

So my recommendation would be to use "Regional info" - it will use .NET built in price formatting and currency symbols based on ISO standards.

Votes for this answer: 1
 
Kristoffer Surrow
Kristoffer Surrow
Reply

I see. 

The difference in formatting is because the method currencyService.Format() seems to be using the "Regional Settings",

while the method currencyService.FormatCurrency() is using the "Regional Info Settings" at the bottom. 

 

This is fine. If I want to change the formatting, this can be done selecting Regional Info: None.

Thanks

My currency setup was like this (rounding was for testing):

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply

Format calls FormatCurrency if needed. So always call Format to follow what Dynamicweb does.

 

You must be logged in to post in the forum