Quantcast
Channel: PowerShell, formatting values in another culture - Stack Overflow
Viewing all articles
Browse latest Browse all 5

Answer by stej for PowerShell, formatting values in another culture

$
0
0

I was thinking about how to make it easy and came up with accelerators:

Add-type -typedef @" using System;   public class InvFloat   {       double _f = 0;       private InvFloat (double f) {           _f = f;     }       private InvFloat(string f) {           _f = Double.Parse(f, System.Globalization.CultureInfo.InvariantCulture);     }       public static implicit operator InvFloat (double f) {           return new InvFloat(f);       }       public static implicit operator double(InvFloat f) {           return f._f;     }       public static explicit operator InvFloat (string f) {           return new InvFloat (f);     }       public override string ToString() {          return _f.ToString(System.Globalization.CultureInfo.InvariantCulture);      } }  "@$acce = [type]::gettype("System.Management.Automation.TypeAccelerators") $acce::Add('f', [InvFloat])$y = 1.5.ToString()$z = ([f]1.5).ToString()

I hope it will help.


Viewing all articles
Browse latest Browse all 5

Trending Articles