Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Community » Newbie corner » display approximation...
display approximation... [message #35738] Thu, 15 March 2012 10:19 Go to next message
idkfa46 is currently offline  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 #35740 is a reply to message #35738] Thu, 15 March 2012 10:46 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3355
Registered: August 2008
Senior Veteran
Hello Matteo

About the last question, the function is StrDbl().


Best regards
Iñaki
Re: display approximation... [message #35742 is a reply to message #35740] Thu, 15 March 2012 11:48 Go to previous messageGo to next message
idkfa46 is currently offline  idkfa46
Messages: 155
Registered: December 2011
Experienced Member
I tryed with

double StrDbl(const char* s);

without any result...
Sure i'm using it in the wrong way Crying or Very Sad
Re: display approximation... [message #35743 is a reply to message #35742] Thu, 15 March 2012 14:10 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3355
Registered: August 2008
Senior Veteran
Hello idkfa46

What do you mean with "without any result...".

Could you detail it?


Best regards
Iñaki
Re: display approximation... [message #35746 is a reply to message #35743] Thu, 15 March 2012 14:56 Go to previous messageGo to next message
idkfa46 is currently offline  idkfa46
Messages: 155
Registered: December 2011
Experienced Member
...
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(s);
	}
}
...


I can't find the right way to convert string to double before adding elements to DropList. How i have to set StrDbl ?!

there are no way to leave them like double and just Display approximate value ?!





Re: display approximation... [message #35748 is a reply to message #35746] Thu, 15 March 2012 15:15 Go to previous messageGo to next message
fudadmin is currently offline  fudadmin
Messages: 1321
Registered: November 2005
Location: Kaunas, Lithuania
Ultimate Contributor
Administrator
What about ScanDouble(..)?
Re: display approximation... [message #35749 is a reply to message #35748] Thu, 15 March 2012 15:43 Go to previous messageGo to next message
idkfa46 is currently offline  idkfa46
Messages: 155
Registered: December 2011
Experienced Member
Yessss....
double n = ScanDouble(s);
working Very Happy

thanks
Re: display approximation... [message #35750 is a reply to message #35749] Thu, 15 March 2012 15:57 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3355
Registered: August 2008
Senior Veteran
Or:

double n = StrDbl(s); Wink


Best regards
Iñaki
Re: display approximation... [message #35751 is a reply to message #35750] Fri, 16 March 2012 12:31 Go to previous message
omari is currently offline  omari
Messages: 264
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.
Previous Topic: Sizeable().Zoomable()
Next Topic: LogPos (and Logc) - what does it mean?
Goto Forum:
  


Current Time: Fri Mar 29 10:58:12 CET 2024

Total time taken to generate the page: 0.01468 seconds