Community discussions

MikroTik App
 
Exodia
just joined
Topic Author
Posts: 4
Joined: Mon Jan 11, 2021 8:46 pm

Remove decimal

Sat Feb 27, 2021 9:21 pm

Hello,

I am learning to write some scripts.
I try to convert a decimal number, the version of the os into an integer
So I use:
/system package update get installed-version
that gives me an output of 6.42.2 for e.g.

Can I convert it into an integer to make some compares?
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3291
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: Remove decimal  [SOLVED]

Sun Feb 28, 2021 10:37 am

This loops trough the string and remove all the dots, then convert it to a number.
{	
:local version [/system package update get installed-version]
:local numVersion
:for i from=0 to=([:len $version]-1) do={
	:local tmp [:pick $version $i]
	:if ($tmp !=".") do={
		:set numVersion "$numVersion$tmp"
		}
	}
:set numVersion [:tonum $numVersion]
:put $numVersion
}
Try cut and past this to command line to see the result.

Based on script found here:
viewtopic.php?t=32125
 
Exodia
just joined
Topic Author
Posts: 4
Joined: Mon Jan 11, 2021 8:46 pm

Re: Remove decimal

Sun Feb 28, 2021 4:28 pm

This loops trough the string and remove all the dots, then convert it to a number.
{	
:local version [/system package update get installed-version]
:local numVersion
:for i from=0 to=([:len $version]-1) do={
	:local tmp [:pick $version $i]
	:if ($tmp !=".") do={
		:set numVersion "$numVersion$tmp"
		}
	}
:set numVersion [:tonum $numVersion]
:put $numVersion
}
Try cut and past this to command line to see the result.

Based on script found here:
viewtopic.php?t=32125
Works perfectly thanks

Who is online

Users browsing this forum: No registered users and 16 guests