|
I've just tried this in .NET 4.0 and 3.5, and the result is the same in both:
float x = 20031010f;
float y = .86f;
float z = x * y;
Console.WriteLine(z);
Console.WriteLine("{0:F}", z);
Output:
1.722667E+07
17226670.00
If your code is returning 1722668.0 then you're doing something wrong; that's off by a factor of 10.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
you are correct and my results are even more evil 17226668.0
I don't doubt I am doing something wrong but really the code is exactly as you demonstrated, simple simple but frustrating.
|
|
|
|
|
Try this:
float z = 20031010f * .86f;
Debug.WriteLine( z.ToString("G") );
The two values ARE equal internally. What you see on screen is just the differnt ways the two environments chose to represent the STRING version of those numbers.
|
|
|
|
|
Yes, but a type like float cannot represent all of the numbers in that range since there are an infinite number of them!
How it works is there are a finite number of bits (32 in this case) to store a floating point value, split into 3 seections. The first bit is the sign bit. The next 8 bits are the exponent value and the remaining 23 bits are the fraction value. This gives you a sum total of 7 digits of numeric representation.
What does that mean? Well, if you want to represent a very large number, the format sacrifices accuracy by rounding off the least significant digits of the fraction value and increasing the value of the exponent to scale the fractional part of the number to the appropriate range.
decimal 10 = 0000001 * 10 ^ 1 (10 ^ 1) = 10
^ ^
| |
fraction exponent
decimal 1234567 = 12D687 * 10 ^ 0 (10 ^ 0) = 1
1234567 can be represented by 21 bits: 1 0010 1101 0110 1000 0111
so it fits inside the 23 bits available for the fraction part.
decimal 12345678 = ??????
Hmmmm... This requires 24 bits to represent: 1011 1100 0110 0001 0100 1110
This won't fit inside the 23 bit fraction part!
What to do, what to do, .... ??
The answer to this little problem is simple. Sacrifice a little precision and use scientific notation! Divide the number by 10 (remember what the exponent is raising) and round it off! This gives us 1234567.8 = 1234568.0. Now, we've got a 7 digit number that fits inside 23 bits. But there's that pesky division we did. Since we divided by 10, we have to raise the value of the exponent to compensate: 10 ^ 1. Now our number looks like this: 1234568.0 * 10 ^ 1, or 1.234568 * 10 ^ 7.
That's the quick'n'grossly simplified version of what's going on. For more read this[^]
modified 26-Feb-13 15:17pm.
|
|
|
|
|
Hi all
I have an annoying problem working with EF5 and Enums, As Enums is supposed to be supported with EF5 I thought this should be an easy matter, but sadly I can't get it behave
I have an Enum
public enum Senddays
{
AllDays = 9,
Monday = 0,
Tuesday = 1,
Wednesday = 2,
Thursday = 3,
Friday = 4,
Saturday = 5,
Sunday = 6
}
And then I have this Class containing a List of said Enums
[Serializable]
public class SubscriptionFrequency
{
public Guid ID { get; set; }
public string Name { get; set; }
public List<Senddays> Senddays { get; set; }
public DeliveryMedia DeliveryMedia { get; set; }
public bool Active { get; set; }
public SubscriptionFrequency()
{
ID = Guid.NewGuid();
}
}
See straight forward.. or so it seems, but when I try to persist it by EF5 It doesn't create a colum for the Senddays List, but eveything else gets in even the DeliveryMedia, which is also an Enum ??
How do I get the List into the DB ?
Best Regards
|
|
|
|
|
You have defined two different meanings of the term 'Senddays' (it's a type, your enum, and a variable, your list). Is it possible EF5 is confused?
|
|
|
|
|
No the definition in the Class : SubscriptionFrequency
is a List of the Enum type .. that should not create any cause for confusion, and it works throughout the code ..
And the DeliveryMedia is also an Enum and that works as intended..
|
|
|
|
|
Hi,
DeliveryMedia is a enum type, so it sets and gets and enum, but List<senddays> is a list containing objects that are cast as Senddays type. so when it has been read you may have to cast it back oreven better if you convert to "List.ToArray()" which will list the values as Senddays type.
Regards
Jegan
Think! Don't write a line of code unless you absolutely need to.
|
|
|
|
|
Hello everyone,
I need C# code for generating a key from fingerprint using minutiae...If anybody have any idea share with me please....
|
|
|
|
|
Please have a look at this paper: Generate a key for MAC Algorithm using
Biometric Fingerprint[^] by Dr.R.Seshadri and T.Raghu Trivedi.
Eventhough I suggest you start reading it from the start, chapter four sounds very promising to your cause: 4. Generating key vector from finger print
After that you can break down your tasks into manageable bits and start coding it. When you run into any specific problems feel free to come back and ask more sensible questions.
Regards,
— Manfre
"I had the right to remain silent, but I didn't have the ability!"
Ron White, Comedian
|
|
|
|
|
Why can't I be really rude to this pillock, has not read the guidelines, asking for the code, the only thing missing is some text speak and a demand for an urgent response!
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
|
Hello
I have a requirement to write pdfdocument using html contents in an ASP.NET MVC Project. I am writing the HTML code inside a string variable and then I am giving that string for rendering it as pdf bytes using the below code. The returned bytes I am saving it as pdf on the server. However I am getting too many formatting issues in the pdf generated.
When I saved the html contents which I passed to the string, formattings are good but somehow when I am trying to create a pdf out of those contents I am getting issues. Any help will be greatly appreciated.
public byte[] Render(string htmlText)
{
byte[] renderedBuffer;
using (var outputMemoryStream = new MemoryStream())
{
using (var pdfDocument = new Document())
{
PdfWriter pdfWriter = PdfWriter.GetInstance(pdfDocument, outputMemoryStream);
pdfWriter.CloseStream = false;
//pdfWriter.PageEvent = new PrintHeaderFooter { Title = pageTitle };
pdfDocument.Open();
using (var htmlViewReader = new StringReader(htmlText))
{
using (var htmlWorker = new HTMLWorker(pdfDocument))
{
htmlWorker.Parse(htmlViewReader);
}
}
}
renderedBuffer = new byte[outputMemoryStream.Position];
outputMemoryStream.Position = 0;
outputMemoryStream.Read(renderedBuffer, 0, renderedBuffer.Length);
}
return renderedBuffer;
}
|
|
|
|
|
krishnapnv wrote: when I am trying to create a pdf out of those contents I am getting issues. And do you plan on letting us into the secret of what those issues are?
Use the best guess
|
|
|
|
|
I am getting issues with formatting. The pdf is not getting formatted properly. A close observation revealted that, itextsharp is not able to include external css files, and so a lot many formatting problems. So I am stuck here and waiting for some response
Thanks
Krishna
|
|
|
|
|
on btn click event how to save windows form data in pdf format
|
|
|
|
|
One way is to use something like iTextSharp to create your PDF.
|
|
|
|
|
|
I have a tabbed form and I'm trying to switch it over to tiled. It looks like this:
TabPage newPage = new TabPage(string.Format("{0}:{1}", cb1.cbInfos[i].usbHandle, cb1.cbInfos[i].boxID));
InitializeControls(controls[i]);
tabCtrlMain.Size = (controls[i].Size);
tabCtrlMain.Width += 20;
tabCtrlMain.Height += 100;
this.Width = tabCtrlMain.Width + 20;
this.Height = tabCtrlMain.Height + 50;
newPage.Controls.Add(controls[i]);
tabCtrlMain.TabPages.Add(newPage);
I saw this example, http://sharpertutorials.com/multiple-document-interface-mdi/[^], but this looks different because they are changing where it refers to Run new Form to Run new Mdi
example:
Application.Run(new Form1());
to
Application.Run(new MDIParent1());
but I'm not seeing where I have that sort of thing to switch over. Does anyone have any ideas how to switch over to tiled from tabbed? I'm fine with the contents of my controls[i] containing the correct information. The tabbed forms look fine. We decided to change the look because we think it will work better with this application. Thanks!
|
|
|
|
|
There's nothing special here. It's really just:
Application.Run(new className);
Instead of calling their startup form the default name of Form1, they changed the name to MDIParent1. Whether of a not a form supports MDI is just a property setting on the form. Just look in the Properties box of your form for "IsMdiContainer".
By the way, everyone is moving AWAY from MDI, not towards it.
After that, I guess you'll have a bunch of code to rewrite as you apparently won't being TabControl anymore. The only person who can tell you what you have to do is yourself since you're the one who designed the app in its current form.
|
|
|
|
|
Cool. That helped. I'm doing this to add it to my existing form and add the existing control that I was previously showing in the tab:
Form newForm = new Form();
InitializeControls(controls[i]);
newForm.Size = (controls[i].Size);
newForm.Width += 20;
newForm.Height += 100;
this.Width = newForm.Width + 20;
this.Height = newForm.Height + 50;
newForm.Controls.Add(controls[i]);
newForm.ShowDialog();
But it's filling up my entire area. Do you know how to scale the control's contents down to 1/4 the size? I think once I do that, it won't be tough to figure out how to position it (tiled) in the right location in my form with the other 4 controls I'm adding. It didn't let me say newForm.size = controls[i].size/4. (operator / can't be applied to system.drawing.size and int)
|
|
|
|
|
Loko at what type the Size property takes, it's an instance of Size. Look at the properties of Size, Height and Width. Sooooo, you just make a new instance of a Size with the new values:
using System.Drawing;
.
.
.
Size newSize = new Size(controls[i].Size.Width / 4, controls[i].Size.Height / 4);
controls[i].Size = newSize;
|
|
|
|
|
Hi,
I want to know how can I force beep using C# and:
[DllImport("kernel32.dll")]
private static extern int Beep(int dwFreq, int dwDuration);
even if Microsoft Windows volume is switched to mute?
Technology News @ www.JassimRahma.com
|
|
|
|
|
Jassim Rahma wrote: even if Microsoft Windows volume is switched to mute? That is the user's choice. I would be very annoyed if some application started beeping after I had set my PC to silent.
Use the best guess
|
|
|
|
|
The only way you can override the sound setting is to change the volume yourself, do the beep, then put the volume back where you found it. There is no little magic "override" method you can call.
The big problem with the is that you're changing a setting the user has set for a reason. THe other one is that if you turn the volume up to some arbitrary level, you have no idea how loud the sound really is. It still might not be audible or you might blast the user right out of their chair!
|
|
|
|