Convert 2 digit after decimal to minutes

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
User avatar
Esabik
Pro Scripter
Posts: 52
Joined: Wed Jun 15, 2005 8:03 pm
Location: Fairfield, NJ

Convert 2 digit after decimal to minutes

Post by Esabik » Mon Jan 03, 2022 4:14 pm

Hi
I am sure this is probably out here, but was not able to find it.

I just want to take for example 4.36 hour and use the .36 convert to minutes as a whole number. ( 4 hr 21 min)etc...
So I was was trying to grab the right most 2 characters and then calculate the minutes. I can't seem to locate the code that lets me get the 2 far right characters from my variable. Rtrim is not what I need even though it looked like it was that since I use seagate crystal lol....
Just when you thought it was safe to go in the water........:evil:

User avatar
Grovkillen
Automation Wizard
Posts: 1131
Joined: Fri Aug 10, 2012 2:38 pm
Location: Bräcke, Sweden
Contact:

Re: Convert 2 digit after decimal to minutes

Post by Grovkillen » Mon Jan 03, 2022 5:28 pm

Use the mod operator: viewtopic.php?f=8&t=10775#p47052
Let>ME=%Script%

Running: 15.0.27
version history

User avatar
Dorian (MJT support)
Automation Wizard
Posts: 1389
Joined: Sun Nov 03, 2002 3:19 am
Contact:

Re: Convert 2 digit after decimal to minutes

Post by Dorian (MJT support) » Mon Jan 03, 2022 5:37 pm

I think either of these get you to where you want to be, or is at least a reasonable starting point. Although I'm sure there may be others here who can find more efficient ways.

Code: Select all

Let>a=4.36
Let>b={frac(%a%)}
Mdl>%b%

let>mins=%b%*60
mdl>mins

Let>c={int(%mins%)}
mdl>%c%

Code: Select all

Let>a=4.36
Let>b={frac(%a%)}
Mdl>%b%

let>mins={int(%b%*60)}
mdl>mins
Yes, we have a Custom Scripting Service. Message me or go here

User avatar
Esabik
Pro Scripter
Posts: 52
Joined: Wed Jun 15, 2005 8:03 pm
Location: Fairfield, NJ

Re: Convert 2 digit after decimal to minutes

Post by Esabik » Mon Jan 03, 2022 6:11 pm

Thank you for responding.

I have worked with a trim that I can get the 2 far right characters from a string with different a software package I used in the past. Its not the same with macro.

I just want to understand how to grab just the 2 digits(from the right) from the variable 4.36 meaning just the “36” which I will convert to min. I dont want the 4 included in my code because that number will always change depending on the qty of records being processed. Hope that helps clear things.

Regards
Just when you thought it was safe to go in the water........:evil:

User avatar
Dorian (MJT support)
Automation Wizard
Posts: 1389
Joined: Sun Nov 03, 2002 3:19 am
Contact:

Re: Convert 2 digit after decimal to minutes

Post by Dorian (MJT support) » Mon Jan 03, 2022 7:38 pm

Can you get the 0.36 using my method then multiply by 100?
Yes, we have a Custom Scripting Service. Message me or go here

User avatar
Esabik
Pro Scripter
Posts: 52
Joined: Wed Jun 15, 2005 8:03 pm
Location: Fairfield, NJ

Re: Convert 2 digit after decimal to minutes

Post by Esabik » Mon Jan 03, 2022 8:24 pm

Dorian (MJT support) wrote:
Mon Jan 03, 2022 7:38 pm
Can you get the 0.36 using my method then multiply by 100?
Well this was not what I was used to, but it works perfect :lol: :lol: . Different software packages and being not a super programmer slows me down lol.

Let>a=4.36
Mdl>%a%

Let>b={frac(%a%)}
Mdl>%b%

let>mins={int(%b%*60)}
mdl>mins

I saw it through the steps and this helps me alot. So if I want to drop the .36 from the 4.36 and use the 4 is that similar code? I am used to a different style of coding, sorry so many questions...
Just when you thought it was safe to go in the water........:evil:

User avatar
Dorian (MJT support)
Automation Wizard
Posts: 1389
Joined: Sun Nov 03, 2002 3:19 am
Contact:

Re: Convert 2 digit after decimal to minutes

Post by Dorian (MJT support) » Mon Jan 03, 2022 8:58 pm

Step-by-step is a great helper when it comes to learning. If you wanted the integer you can use int.

Code: Select all

Let>a=4.36
Let>b={int(%a%)}
Mdl>%b%
Here's a handy list of Arithmetic Functions and Arithmetic Operators.
Yes, we have a Custom Scripting Service. Message me or go here

User avatar
Dorian (MJT support)
Automation Wizard
Posts: 1389
Joined: Sun Nov 03, 2002 3:19 am
Contact:

Re: Convert 2 digit after decimal to minutes

Post by Dorian (MJT support) » Mon Jan 03, 2022 8:59 pm

I should also point out that while my samples contain single character variables, they should generally be avoided.
Yes, we have a Custom Scripting Service. Message me or go here

User avatar
Esabik
Pro Scripter
Posts: 52
Joined: Wed Jun 15, 2005 8:03 pm
Location: Fairfield, NJ

Re: Convert 2 digit after decimal to minutes

Post by Esabik » Mon Jan 03, 2022 9:57 pm

Dorian (MJT support) wrote:
Mon Jan 03, 2022 8:58 pm
Step-by-step is a great helper when it comes to learning. If you wanted the integer you can use int.

Code: Select all

Let>a=4.36
Let>b={int(%a%)}
Mdl>%b%
Nice this is very arhythmical, but what if my values are all alpha and I was say the last 3 places from a string which has value form my data?

balluny
ballsny
ballphl

If I can ask, how would I extract the "uny" if that was perhaps locations from a data sort that are not numbers? Is there a function that can parse it?
Just when you thought it was safe to go in the water........:evil:

User avatar
Dorian (MJT support)
Automation Wizard
Posts: 1389
Joined: Sun Nov 03, 2002 3:19 am
Contact:

Re: Convert 2 digit after decimal to minutes

Post by Dorian (MJT support) » Mon Jan 03, 2022 10:27 pm

There's always Regex, but check out Length MidStr and generally the String Functions.

So, to get the last 3 characters of a string :

Code: Select all

let>MyString=balluny
len>MyString,MyStringLen
let>Last3Pos=MyStringLen-2

MidStr>MyString,Last3Pos,3,Last3Chars
MDL>Last3Chars
Yes, we have a Custom Scripting Service. Message me or go here

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts