Add a Text to a number

This topic contains 3 replies, has 3 voices, and was last updated by Profile photo of 37mm 37mm 11 months ago.

  • Author
    Posts
  • #33478
    Profile photo of 37mm
    37mm
    Participant

    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
    Profile photo of random commandline
    random commandline
    Participant

    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
    Profile photo of Tim Pringle
    Tim Pringle
    Participant

    Another way is simply to cast it to a string :

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

    Thanks fellas!

You must be logged in to reply to this topic.