Author |
Topic  |
|
VanAwful
USA
13 Posts |
Posted - 10/15/2018 : 6:28:34 PM
|
Working with 2018b, build b9.5.5.409 on Windows 10. How can I extract a single digit from a number and assign to an int? I have a data output that puts the time as hhmmss.nnn. I need to convert this to seconds.miliseconds. In excel I can just use left, mid, and right to extract the digits. I can then convert each to seconds and add. Left, Mid, and Right will work by themselves in the column F(x), but not when combined and not in the formula script.
Currently I am converting the whole number to a string, extracting, then converting back. This is a messy way and looking for a more straight forward method. |
|
Castiel
343 Posts |
Posted - 10/15/2018 : 10:00:28 PM
|
quote: Originally posted by VanAwful
Working with 2018b, build b9.5.5.409 on Windows 10. How can I extract a single digit from a number and assign to an int? I have a data output that puts the time as hhmmss.nnn. I need to convert this to seconds.miliseconds. In excel I can just use left, mid, and right to extract the digits. I can then convert each to seconds and add. Left, Mid, and Right will work by themselves in the column F(x), but not when combined and not in the formula script.
Currently I am converting the whole number to a string, extracting, then converting back. This is a messy way and looking for a more straight forward method.
That "but not when combined and not in the formula script" should have been described in details.
Say, the string you have is "123456.123": string x$="123456.123"; Now convert it to double: double t = time(x$, "HHmmss.###"); To get hour/minute/second: int h = hour(t); // d = 12
int m = minute(t); // m = 34
double s = second(t); // s = 56.123
#####
#### _\_ ________
##=-[.].]| \
#( _\ | |------|
# __| | ||||||||
\ _/ | ||||||||
.--'--'-. | | ____ |
/ __ `|__|[o__o]|
_(____nm_______ /____\____
|
 |
|
VanAwful
USA
13 Posts |
Posted - 10/16/2018 : 11:47:26 AM
|
My apologies, yes, I did not post enough information. I am new to Origin.
In my workbook, I have a numerical value of 165703.685 in cell B1. In column A if I put left(Col(B),2) in F(x), then cell A1 shows 16. However, I am not able to use formula left(Col(B),2)*60 to convert from 16 hours to minutes. Note the value in B1 is numerical, not string.
I must convert this to readable 24hour time format: 16:57:03.685 For another use I must also convert this to seconds: 61023.685
I've found that I cannot combine methods like I do in excel, such as: left(Col(B),2)*60
Now, in the script I am now doing it this way for the total seconds:
h = left(Col(B),2); m = mid(Col(B),3,2); s = mid(Col(B),5,6);
ts=(h*60*60)+(m*60)+s;
I am still working on the conversion to the format HH:mm:ss.###.
|
 |
|
Castiel
343 Posts |
Posted - 10/16/2018 : 10:08:56 PM
|
quote: Originally posted by VanAwful
My apologies, yes, I did not post enough information. I am new to Origin.
In my workbook, I have a numerical value of 165703.685 in cell B1. In column A if I put left(Col(B),2) in F(x), then cell A1 shows 16. However, I am not able to use formula left(Col(B),2)*60 to convert from 16 hours to minutes. Note the value in B1 is numerical, not string.
I must convert this to readable 24hour time format: 16:57:03.685 For another use I must also convert this to seconds: 61023.685
I've found that I cannot combine methods like I do in excel, such as: left(Col(B),2)*60
Now, in the script I am now doing it this way for the total seconds:
h = left(Col(B),2); m = mid(Col(B),3,2); s = mid(Col(B),5,6);
ts=(h*60*60)+(m*60)+s;
I am still working on the conversion to the format HH:mm:ss.###.
Given B1 = 165703.685,
1) To show as HH:mm:ss.### in A1, you should double click on Column A to open the Column Properties, in which you may set Format = Time and Dislay = HH:mm:ss.###. The formula for Column A is time(B,"HHmmss.###")
2) To convert it to seconds in Column C, the formula can be hour(A)*3600+minute(A)*60+second(A)
That left(Col(B),2)*60 fails as left() returns a string. This works: value(left(col(B),2))*60
#####
#### _\_ ________
##=-[.].]| \
#( _\ | |------|
# __| | ||||||||
\ _/ | ||||||||
.--'--'-. | | ____ |
/ __ `|__|[o__o]|
_(____nm_______ /____\____
|
 |
|
VanAwful
USA
13 Posts |
Posted - 10/17/2018 : 3:34:01 PM
|
Castiel, thank you very much. What you provided works very good. 
I really like Origin and looking forward to learning much more. |
 |
|
|
Topic  |
|
|
|