|
|
Home » Community » Newbie corner » display approximation...
display approximation... [message #35738] |
Thu, 15 March 2012 10:19  |
idkfa46
Messages: 155 Registered: December 2011
|
Experienced Member |
|
|
Hallo guys,
I'm here with a new question about DropList!
Here the incriminate code:
dl = DropList
value = EditDouble
void DLprove::compute()
{
// DropList elements...
dl.Clear();
for(int i=1; i<=value; ++i)
{
double k= value/i;
if ( k > 5 && k < 45 )
{
dl.Add(k);
}
}
// SetIndex the nearest element to "17"
int idx = -1;
double mind = 1e9;
for(int i = 0; i < dl.GetCount(); i++)
{
double d = fabs((double)dl.GetValue(i) - 17);
if(d < mind)
{
mind = d;
idx = i;
}
}
if(idx >= 0)
dl.SetIndex(idx);
}
How can be possible to display the dropdown with an approximation without converting double to string ?
I tryed setting
String s = Format("%.02f", k);
but i have a issue looking for the nearest value to 17...
If "string" is the only solution to display approximate values, how can be possible to convert back string to double before
double d = fabs((double)dl.GetValue(i) - 17);
At the moment application with String compile correctly but applicazion gonna crash.
Here the fatal error:
"Assertion failed in c:\upp\uppscr\core\Value.h, line 474
Invalid value conversion: class Upp::RichValueRep <class Upp::String> -> double
Regards,
Matteo
|
|
|
|
|
|
|
|
|
|
Re: display approximation... [message #35751 is a reply to message #35750] |
Fri, 16 March 2012 12:31  |
omari
Messages: 276 Registered: March 2010
|
Experienced Member |
|
|
Hello ,
you can try that:
use dl.Add(key, value);
dl.Clear();
for(int i=1; i<=value; ++i)
{
double k= value/i;
if ( k > 5 && k < 45 )
{
String s = Format("%.02f", k); // convert to string
//double StrDbl(const char *s);// back to double
dl.Add(k, s);
}
}
then to get the DropList value: use GetKey()
double d = fabs((double)dl.GetKey(i) - 17);
regards
omari.
|
|
|
Goto Forum:
Current Time: Mon May 12 10:32:24 CEST 2025
Total time taken to generate the page: 0.01095 seconds
|
|
|