0

There are some folder. For example 0.8, 0.9, 1.0. Between the these name max number is 1.0. Actually ı can find value. But I want to write as "1.0" format to .txt file.

$maxvalue = ($var | Measure -Max).Maximum
 $vers = 'v'+$maxvalue

find the max value in $var strings. When I want to bring 'v' character to this name it looks like v1. But I want to be like v1.0 for other file process in my code. How can protect this name with ".0" caracter and add text file. Thanks for your support

PALES
  • 7
  • 2
  • Welcome to SO. You may (re-)read the help topic [ASK]. Please elaborate a little more detailed about your task. – Olaf Apr 17 '20 at 09:50

1 Answers1

1

If in your current locale settings, you use the decimal point (.), this should do it:

$vers = 'v{0:F1}' -f $maxvalue

However, if (like it is for me), the current locale setting is e decimal comma (,), you need to either temporarily set the current culture to for instance 'en-US':

$oldCulture = [cultureinfo]::CurrentCulture
[cultureinfo]::CurrentCulture = 'en-US'
$vers = 'v{0:F1}' -f $maxvalue
[cultureinfo]::CurrentCulture = $oldCulture

Or do:

$vers = 'v' + $maxvalue.ToString("F1",[cultureinfo]::InvariantCulture)

Please also have a look at the excellent explanation by mklement0

Theo
  • 57,719
  • 8
  • 24
  • 41
  • Thanks this answer. It helps the understanding logical behid in this subject. After some trying I found like this step : `$vers = 'v'+$maxvalue + '.0'`. May be it helps for anyone. – PALES Apr 20 '20 at 11:06
  • @PALES That won't do if your `$maxvalue` happens to be 1.1. Simply adding `".0"` to it will leave you with `v1.1.0` – Theo Apr 20 '20 at 11:09
  • Thanks your remember. I used the this `$vers = 'v'+$maxvalue + '.0` code only v1.0 or v2.0 condition. In other conditions likes v0.1, v1.2, v3.5 I don't use extran '.0' adding things. Actually this problem is happening when I found the max version is 1.0 then I want to write to v1.0 to text file bu it wrote 'v1' not 'v1.0'(I thing because of th powershell accept it as a integer value.). If I found the max version is 0.6, 1.1,.. I can't write normally v0.6, v1.1,.. without any code. – PALES Jun 02 '20 at 06:51