none
ToGB() decimal places RRS feed

  • Question

  • Hi All,

    I have this piece of code which outputs the values to a html file.

    (get-mailboxdatabase)|foreach-object {
     $database= $_.name
     $accounts= (get-mailbox -database $_.name).count
     $size = (get-mailboxdatabase $_.name -status).databasesize.ToMB()/1024

         add-content $wfile "<tr>"
         add-content $wfile "<td align= 'center'>$database</td>"
         add-content $wfile "<td align= 'center'>$Accounts</td>"
         add-content $wfile "<td align= 'center'>$size</td>"   
     }

    My issue I can't get the size to output to 2 decimal places it outputs 8 decimal places.

    If I use ToGB() instead of ToMB()/1024 I only get the whole number

    I have tried using {N0:02} but it doesn't help

    What am I doing wrong?

    TIA

    Andy

    Monday, February 23, 2015 11:39 AM

Answers

  • How are you applying the format string?

    $size = '{0:N2}' -f  ((get-mailboxdatabase $_.name -status).databasesize.ToMB()/1024)



    [string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "

    • Marked as answer by UKMorite Monday, February 23, 2015 2:58 PM
    Monday, February 23, 2015 12:40 PM
    Moderator

All replies

  • How are you applying the format string?

    $size = '{0:N2}' -f  ((get-mailboxdatabase $_.name -status).databasesize.ToMB()/1024)



    [string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "

    • Marked as answer by UKMorite Monday, February 23, 2015 2:58 PM
    Monday, February 23, 2015 12:40 PM
    Moderator
  • Perfect, Thank you
    Monday, February 23, 2015 2:58 PM