Decimal separator changes when double is concatenated to a string

Welcome Forums General PowerShell Q&A Decimal separator changes when double is concatenated to a string

Viewing 2 reply threads
  • Author
    Posts
    • #210294
      Participant
      Topics: 1
      Replies: 1
      Points: -4
      Rank: Member

      I’m trying to concatenate a string and a double and I get a strange result. Using this test script

      Get-Culture
      $s = "Hello"
      $d = 0.12345
      $t = $s+" " + $d
      
      
      
      $s
      $d
      $t
      
      

      I get this result

      LCID             Name             DisplayName                                                                                                                            
      ----             ----             -----------                                                                                                                            
      1053             sv-SE            Swedish (Sweden)                                                                                                                       
      Hello
      0,12345
      Hello 0.12345

      $d decimal separator has changed from comma to point!

      Why and how do I keep the comma?

       

      // Anders

    • #210297
      Participant
      Topics: 4
      Replies: 2231
      Points: 5,414
      Helping Hand
      Rank: Community MVP

      You could use the -f format operator …

      $s = "Hello"
      $d = 0.12345
      "{0} {1}" -f $s, $d
    • #210300
      Participant
      Topics: 1
      Replies: 1
      Points: -4
      Rank: Member

      Works perfectly!

      Thank you very much!

      //Anders

Viewing 2 reply threads
  • You must be logged in to reply to this topic.