Reputation: 333
I have a small ASP.NET MVC site that displays salary details for employees.
<td align="right">@String.Format("{0:c}", Model.Salary)</td>
On my local machine this displays fine e.g. £66,000, however when uploaded to Azure it is displaying with a dollar e.g. $66,000.
When setting up I chose western Europe as my location but I obviously need to do something else tfor this to display in £s. Any ideas?
Upvotes: 4
Views: 8781
Reputation: 11
I was running into this problem trying to use Microsoft HPC Server 2012 worker roles in Azure. I needed every user who submitted work to the machine to be set to en-GB rather than en-US, mainly due to date formatting issues within the client application.
My solution was to amend the Default User NTUSER.DAT file, which is the template all future users are created from. Using this particular worker role, that file was stored in D:\Users\Default User\NTUSER.DAT
although our physical servers locate it in C.
You can't see that file in Windows Explorer unless you go to folder options and uncheck Hide protected operating system files AND check show hidden files.
You can then make any changes you wish to the user registry keys, the next user to create a profile will then inherit those settings. Since Azure startup scripts run before any local users are created, you can force all new users to inherit these defaults.
Here is a PowerShell script that ensures Azure Worker roles use en-GB and not en-US
[CmdletBinding(SupportsShouldProcess=$True)]
Param(
[string]
$NTUserDatPath = "D:\Users\Default User\NTUSER.DAT"
)
If(!(Test-Path $NTUserDatPath)){
" Write-Error $NTUserDatPath incorrect"
}
REG load HKLM\TempHive $NTUserDatPath
$Default = "HKLM:\TempHive\Control Panel\International"
Set-ItemProperty -Path $Default -Name "iCountry" -Value "44" -Force
Set-ItemProperty -Path $Default -Name "Locale" -Value "00000809" -Force
Set-ItemProperty -Path $Default -Name "LocaleName" -Value "en-GB" -Force
Set-ItemProperty -Path $Default -Name "sCountry" -Value "United Kingdom" -Force
Set-ItemProperty -Path $Default -Name "sCurrency" -Value "£" -Force
Set-ItemProperty -Path $Default -Name "sLanguage" -Value "ENG" -Force
Set-ItemProperty -Path $Default -Name "sLongDate" -Value "dd MMMM yyyy" -Force
Set-ItemProperty -Path $Default -Name "sShortDate" -Value "dd/MM/yyyy" -Force
Set-ItemProperty -Path $Default -Name "sTimeFormat" -Value "HH:mm:ss" -Force
Set-ItemProperty -Path $Default -Name "sShortTime" -Value "HH:mm" -Force
Set-ItemProperty -Path $Default -Name "iDate" -Value "1" -Force
Set-ItemProperty -Path $Default -Name "iFirstDayOfWeek" -Value "0" -Force
Set-ItemProperty -Path $Default -Name "iFirstWeekOfYear" -Value "2" -Force
Set-ItemProperty -Path $Default -Name "iMeasure" -Value "0" -Force
Set-ItemProperty -Path $Default -Name "iNegCurr" -Value "1" -Force
Set-ItemProperty -Path $Default -Name "iPaperSize" -Value "9" -Force
Set-ItemProperty -Path $Default -Name "iTime" -Value "1" -Force
Set-ItemProperty -Path $Default -Name "iTLZero" -Value "1" -Force
REG unload HKLM\TempHive
Here is the live GitHub version
Upvotes: 1
Reputation: 8606
You need to set specific culture at application level in web.config as below
<configuration>
<system.web>
<globalization uiCulture="en-GB" culture="en-GB" />
</system.web>
</configuration>
Alternatively you can also set below to Application_PreRequestHandlerExecute() in global.asax file
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("en-GB");
Upvotes: 19
Reputation: 24895
This issue is not related to Windows Azure but it simply comes down to localization (the default culture on your machine is probably different from the one in Windows Azure). Try changing the culture to en-GB:
public ActionResult DoSomething()
{
System.Threading.Thread.CurrentThread.CurrentCulture
= new System.Globalization.CultureInfo("en-GB");
System.Threading.Thread.CurrentThread.CurrentUICulture
= new System.Globalization.CultureInfo("en-GB");
...
model.Salary = 66.000;
return View(model)
}
Upvotes: 2