|
that will take too much time, i have about 1 lakh strings, please tell any short way
Becoming Programmer...
|
|
|
|
|
This seems a little clumsy but it works
float b = (float)Math.Round(decimal.Parse(a), 4);
The Math.Round method uses 'Bankers Rounding' which may not acheive the result you require. If not you may need to use this which is even clumsier
float b = float.Parse(decimal.Parse(a).ToString("N4"));
Dave
|
|
|
|
|
DaveyM69 wrote: float b = float.Parse(decimal.Parse(a).ToString("N4"));
thanks, it works
Becoming Programmer...
|
|
|
|
|
DaveyM69 wrote: This seems a little clumsy but it works
float b = (float)Math.Round(decimal.Parse(a), 4);
That's not clumsy at all. That's exactly what I would suggest.
DaveyM69 wrote: The Math.Round method uses 'Bankers Rounding' which may not acheive the result you require. If not you may need to use this which is even clumsier
float b = float.Parse(decimal.Parse(a).ToString("N4"));
Now, that is clumsy. Converting a string to a double, to a string, to a float... Why is there no base64 and serializing to xml in there?
If you want a different kind of rounding, just specify that in the call to Round:
float b = (float)Math.Round(decimal.Parse(a), 4, MidpointRounding.AwayFromZero);
Experience is the sum of all the mistakes you have done.
|
|
|
|
|
Guffa wrote: Why is there no base64 and serializing to xml in there?
I did say it was even clumsier!
I haven't come across MidpointRounding.AwayFromZero before - more learning to do
Dave
|
|
|
|
|
Hi,
if the values well are within int limits, then you can do things such as:
float b = Convert.ToSingle(a);
int b4= (int)(10000.0*b+0.5);
b=0.0001*b4;
This does not create any objects; variants of it will all have similar performance.
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
i think DaveyM69 gave good solution, anyway thank you too
Becoming Programmer...
|
|
|
|
|
The bankers rounding, is that what you want?? (you do realize it produces even numbers only?)
or the clumsy and slow one with an unnecessary ToString() and Parse()??
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
no, i dont want bankers rounding,
yeah i know your way is good, but a little bit long as i have to write it about in 100 lines in a big loop
so you can think 100 * 3 repeating lines will hard to understand and a little mistake can destroy the project
Becoming Programmer...
|
|
|
|
|
Hi,
you can put all three lines in a single one (not recommended).
you can turn it into a little method.
anyway, if you think you need it a hundred times, chances are there is something
wrong with your data representation to begin with. Normally there is no need to do so,
using arrays or collections should avoid a lot of code duplication (which normally is
a bad idea).
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
oh yeah, a method is good idea, thanks
Becoming Programmer...
|
|
|
|
|
public static double GetValue(string what)
{
return multiplierDivider * (int)(multiplier * Convert.ToSingle(what) + 0.5);
}
what do you think about it
Becoming Programmer...
|
|
|
|
|
Luc Pattyn wrote: The bankers rounding, is that what you want?? (you do realize it produces even numbers only?)
No, it only rounds to an even number if the number is right in the middle of two possible results. I.e. both 1.00015 and 1.00025 would both be rounded to 1.0002, but 1.00014 would still be rounded to 1.0001.
Experience is the sum of all the mistakes you have done.
|
|
|
|
|
Hi Guffa, you're right.
I forgot the details, since I decided long ago it was of no value to me.
I'm an engineer, so for me if 1.00015 rounds up, so should 1.00025
And I never understood the advantage, if any, of the banker's rounding.
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
Luc Pattyn wrote: And I never understood the advantage, if any, of the banker's rounding.
The advantage is that in the long run it will round up just as many times as down. If you are doing millions of transactions, and the roundings doesn't even out in the end, you may loose a lot of money.
For us non-bankers, consistency makes more sense.
Experience is the sum of all the mistakes you have done.
|
|
|
|
|
I see. thanks.
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
I am creating DataGridView dynamically could anybody tell me how to set
tab order for the same.
Truth Is The Simplest !!!!
|
|
|
|
|
tab order of DataGirdView!!!
AFAIK i know you are talking about column order of DGV, if yes then you can not change column order in one line, you need to delete all columns then add in the required order
Becoming Programmer...
|
|
|
|
|
i try the code,
<;asp:buttonfield buttontype="image" imageurl="~/Image/Blue hills.jpg" commandname="Select" />
but it accept single image .i want image folder or '<%# Eval("exe")%>'
|
|
|
|
|
you can't set imageUrl to a folder...
i think you should look at Repeater or adrotator control for that
|
|
|
|
|
i set image in my folder,
<asp:ImageButton ID="Image1" runat="server" ImageUrl='<%# Eval("filename")%>;'OnCommand="ImageButtonCommandHandler" Width="150px"/>
i show all image in grid view but how to show particular related .exe file in image click event.
|
|
|
|
|
Morning,
I've spent ages trying to sort this problem and I've got nowhere. I was just wondering if anyone here had some across it before.
The best way to describe it is with picutres
with problem[^]
As you can see on the above picutre the display is "mangled", showing through to the window below and generally looking corupt.
If I force a refresh (this.Refresh()) then it renders correctly as shown on:
without problem[^]
As the problem seems to occure everytime the data on the form is changed in anyway (add to table, resize form etc) I don't really want to manually force refreshes all the time in order to sort it.
At first I thought this problem was due to graphics card/driver issue on my development machine but after testing this on 4 other machines (all different specs) I'm not so sure as the problem was present on those machines as well.
Any ideas would be very welcome.
Thanks
Sam
|
|
|
|
|
Just a bit more info.
The DataGridView on the form is one that I have subclassed from System.Windows.Forms.DataGridView
It has the following handler declared in its ctor.
this.CellFormatting +=new DataGridViewCellFormattingEventHandler(DGVEnhanced_CellFormatting);
If I comment this out then the problem goes away. If I leave it in (even if the DGVEnhanced_CellFormatting function is empty and does nothing, then the fault resurfaces. Very strange...
|
|
|
|
|
Now i am working gridview so convert this code and replay to me..
modified on Saturday, February 16, 2008 7:19 AM
|
|
|
|
|
I have wizard kind of Windows Application with Forms having Prev and Next buttons. Currently i have set the Location for all the Forms on Form_Load() method using this.Location = new Point(100, 100);
Now my requirement is that when using "Extend my Windows desktop onto this monitor” setting in Display/Settings Properties, the form should stay in the user’s selected monitor. When i go to the Next form it defaults to the main monitor.
I tried removed the size setting on Form_Load but when i navigate to the next/prev forms the location of the form is not properly set. It randomly positions itself.
How can i do this?
|
|
|
|