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 previous 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
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Sizeable().Zoomable()
Next Topic: LogPos (and Logc) - what does it mean?
Goto Forum:
  


Current Time: Mon Apr 29 10:24:07 CEST 2024

Total time taken to generate the page: 0.02654 seconds