Add a Text to a number

Welcome Forums General PowerShell Q&A Add a Text to a number

This topic contains 3 replies, has 3 voices, and was last updated by

 
Participant
2 years, 9 months ago.

  • Author
    Posts
  • #33478

    Participant
    Points: 0
    Rank: Member

    I have this string
    ([math]::Round(($data.temperature.min – 273.15)*9/5+32))
    I am try to append a F for Fahrenheit to the string.
    Having a brain fart.

  • #33481

    Participant
    Points: 0
    Rank: Member

    You can use the format operator to create formatted strings.

     "{0} (F)" -f ([math]::Round(($data.temperature.min - 273.15)*9/5+32)) 

    Result: -460 (F)

  • #33482

    Participant
    Points: 0
    Rank: Member

    Another way is simply to cast it to a string :

    [string] ([math]::Round(($data.temperature.min – 273.15)*9/5+32) )+ 'F' 
  • #33486

    Participant
    Points: 0
    Rank: Member

    Thanks fellas!

The topic ‘Add a Text to a number’ is closed to new replies.