Numbers formatting in C# -


i have numbers this: -1.0001 -10000.01

and need this: -1.0001 -10000,01

requirements: - decimal separator "," - group separator " " - part of number after comma can have different length, depends actual data.

i tried use mask: "### ### ##0.####" format numbers. when number big - ok, when small - spaces left of number. this: "- 1,0001" "- 10 000,01"

as understand these spaces mask used.

there workaround ways not beautiful , aesthetically wright.

is there way correctly?

thank you!

try using numberformatinfo class format number. used code below check answer , worked large/small cases tested with:

    static void main(string[] args)     {         double smallnumber = -1.01;         double smallnumbermoredigits = -1.0001;         double bignumber = -100000.001;         double longnumber = 2.2347894612789;          thread.currentthread.currentculture = new cultureinfo("ru", false);                      console.out.writeline(smallnumber.tostring("#,0.####"));         console.out.writeline(smallnumbermoredigits.tostring("#,0.####"));         console.out.writeline(bignumber.tostring("#,0.####"));         console.out.writeline(longnumber.tostring("#,0.####"));          console.read();     } 

edit: quick bit of detective work (i looked @ profile) tells me you're in russia. looking general russian number formatting? i've changed code above. take , see if fits requirements. gives me following results:

-1,01 -1,0001 -100000,001

second edit: added masking better result on decimal places.


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -