Convert 2 digit after decimal to minutes
Moderators: Dorian (MJT support), JRL
Convert 2 digit after decimal to minutes
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....
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........
- 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
Use the mod operator: viewtopic.php?f=8&t=10775#p47052
- Dorian (MJT support)
- Automation Wizard
- Posts: 1389
- Joined: Sun Nov 03, 2002 3:19 am
- Contact:
Re: Convert 2 digit after decimal to minutes
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
Re: Convert 2 digit after decimal to minutes
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
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........
- Dorian (MJT support)
- Automation Wizard
- Posts: 1389
- Joined: Sun Nov 03, 2002 3:19 am
- Contact:
Re: Convert 2 digit after decimal to minutes
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
Re: Convert 2 digit after decimal to minutes
Well this was not what I was used to, but it works perfect . Different software packages and being not a super programmer slows me down lol.Dorian (MJT support) wrote: ↑Mon Jan 03, 2022 7:38 pmCan you get the 0.36 using my method then multiply by 100?
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........
- Dorian (MJT support)
- Automation Wizard
- Posts: 1389
- Joined: Sun Nov 03, 2002 3:19 am
- Contact:
Re: Convert 2 digit after decimal to minutes
Step-by-step is a great helper when it comes to learning. If you wanted the integer you can use int.
Here's a handy list of Arithmetic Functions and Arithmetic Operators.
Code: Select all
Let>a=4.36
Let>b={int(%a%)}
Mdl>%b%
Yes, we have a Custom Scripting Service. Message me or go here
- Dorian (MJT support)
- Automation Wizard
- Posts: 1389
- Joined: Sun Nov 03, 2002 3:19 am
- Contact:
Re: Convert 2 digit after decimal to minutes
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
Re: Convert 2 digit after decimal to minutes
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?Dorian (MJT support) wrote: ↑Mon Jan 03, 2022 8:58 pmStep-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%
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........
- Dorian (MJT support)
- Automation Wizard
- Posts: 1389
- Joined: Sun Nov 03, 2002 3:19 am
- Contact:
Re: Convert 2 digit after decimal to minutes
There's always Regex, but check out Length MidStr and generally the String Functions.
So, to get the last 3 characters of a string :
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