The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum for Programming
 Forum for Origin C
 setting precision
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

shafei

USA
49 Posts

Posted - 02/07/2012 :  1:51:51 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Ver. and Service Release (Select Help-->About Origin):8.1
Operating System:7

Hi,
I was wondering if Origin C has a command like "setprecision" in C++.
In my code in Origin C, I generate some random numbers. Instead of having a number of the form 12.3454937 I would like to generate one like 12.34. Is there a command for that?
Thanks

Penn

China
644 Posts

Posted - 02/07/2012 :  9:33:00 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

Please try the prec function.

Penn
Go to Top of Page

shafei

USA
49 Posts

Posted - 02/07/2012 :  9:39:49 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Works great! Thank you very much.
Go to Top of Page

shafei

USA
49 Posts

Posted - 02/13/2012 :  2:51:46 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
I tried the code to generate some numbers with the command
x = prec(rnd() * 10, 4); and that's what I get:
7.94406
0.80123
6.32973
,etc.
What is wrong?!
I have Origin 8.1
Go to Top of Page

Penn

China
644 Posts

Posted - 02/13/2012 :  9:40:13 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

I have tried the command you mentioned in Origin 8.1, however, I am afraid that I cannot reproduce the problem. If possible, you can try in other computer to see whether the problem can be reproduced.

Penn
Go to Top of Page

shafei

USA
49 Posts

Posted - 02/14/2012 :  02:24:50 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Penn,
I generate array of x[i]s and y[i]s randomly and use them for some other calculations. I get numbers like 3.459057 while I like one like 3.46. The "prec" command works great when I just use it and printf numbers. However, when I transfer this numbers into a worksheet, using the same code I have written, the raw numbers like 3.459057 appears there.
So let me explain the process in details:
1. I randomly generate x[i] and y[i] where I use prec command and also I have xaux[i]=x[i] and yaux[i]=y[i].
2. I do use them some calculations and some of them are stored as xmax[i] and ymax[i]. Then these values are printed out in a worksheet. Here, instead of seeing desired numbers, i.e. 3 significant digit, the numbers have 5 or 6 significant digits.
Go to Top of Page

Penn

China
644 Posts

Posted - 02/14/2012 :  03:16:23 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

The problem may be the calculations you have performed on the data. The data you used for calculations is with four significant digits, however, the results will not also be with four significant digits. If you want to have 4 significant digits for the results, you can use the prec function to make the results with four significant digits. In your case, maybe you can do like this:

xmax[i] = prec(xmax[i]);
ymax[i] = prec(ymax[i]);


Penn
Go to Top of Page

atashawn

1 Posts

Posted - 03/08/2012 :  07:48:21 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
This is quite interesting. I'd make a further research about this matter. Thank you for this input.
Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000