Dealing with floats

1. Senior Member
Join Date
Dec 1969
Posts
299

## Dealing with floats

I have a method that performs a little math on an integer. It is supposed to reduce a number by a given percent. It is as follows:<BR><BR>=====================CODE========= ================<BR><BR> private int ReduceBy(int val)<BR> { <BR> if (reduceby != 0)<BR> {<BR> float percentval = reduceby / 100;<BR> float subtractval = val * percentval;<BR> float returnval = val - subtractval;<BR> return (int)returnval;<BR> }else{<BR> return val;<BR> }<BR> }<BR><BR>========================================= ===========<BR><BR>the argument and the return value MUST be an integer because of the specifics. However, when I run this method the argument is not changed when it returns. I believe this is because something is getting lost in the cast and is ultimately subtracting by zero. <BR><BR>Is there a way to perform this operation? It is ok if the final integer is reduced, lets say it should be reduced from 40 to 22.4 it&#039;s ok if the .4 is lost, but it should not be returned 40.<BR><BR>Thanks in advance, hope that explanation was clear.

2. Junior Member
Join Date
Dec 1969
Posts
5

## RE: Dealing with floats

Maybe I am missing something, but I don&#039;t see where reduceby is coming from. The only parameter I see that you are passing is val. Is reduceby set somewhere else, or is this supposed to be passed into the function. If reducedby isn&#039;t passed and you don&#039;t have it set anywhere, it might be just running else code, not the code that reduces the value.

3. Senior Member
Join Date
Dec 1969
Posts
299

## RE: Dealing with floats

never mind got it. It was in fact getting lost in a cast, but it was lost during a boxing operation after the value was returned. If anyone is interested in this custom control it&#039;s pretty neat, and usefull.<BR>------------------------<BR>ThumbMaker.dll<BR><BR>Usage:<BR><BR>&#060;Cust om:ThumbMaker Path="Some Directory" ReduceByPercent="n" /&#062;<BR><BR>Purpose:<BR><BR>It will go to the directoy specified under PATH and display all image files reduced from their original size by the percentage "n" supplied in REDUCEBYPERCENT. It will also provide a link to the original image at it&#039;s original size. (The reduced image is the link)<BR><BR>It&#039;s available for download free at www.retrofusion.cc<BR><BR>---------------<BR><BR>My digital camera dumps all it&#039;s images in a folder which I upload. It&#039;s certainly a pain to set up a page for each image. Especially when new ones are added and others are removed so frequently. This will take all the guess work out of it.

4. Senior Member
Join Date
Dec 1969
Posts
2,930

## kinda like this?

http://www.jasontconnell.com/pictures.asp<BR><BR>hehehe that shows if a file is "New" too, by testing the create date against the current, if it&#039;s less than a month old it prints "New!" next to it. also have slideshows... no thumbnails though, didn&#039;t want to download huge images just to show a thumbnail of it...<BR><BR>that is a pretty neat control though. if my digital camera took smaller images i would make one like that but since they&#039;re huge, i shrink them in an image editor then upload them, and show only filenames and flag new images to save download time. that was made in my pre .net age. if i had it all to do over again, i&#039;d do it in .net now (or java) :-P

5. Senior Member
Join Date
Dec 1969
Posts
299

## RE: kinda like this?

****, now that date thing I wouldnt&#039; have thought of in a million years. Bravo. I wrote the control in response to a question posted above. Then I thought, hey, I could use this. After I finished I wrote up a quick article on how to use it and posted it. I surfed around a little and realized, not only are there about a million others like it, .NET even provides the GetThumbnail() method for the image object!!!! HA! how&#039;s that for a bubble popper! <BR><BR>Well done on your image solution.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•