|
We all know Math.Round() basically rounds a particular decimal value. But if we look into this method closely it rounds the value to the nearest even value.
For example if we do Math.Round(2.5,0) it will return 2. But we may expect 3 intead of 2. In that case we can use MidPointRounding parameter of
Math.Round() method.
Math.Round can also take a parameter known as MidPointRounding which helps us to select the Rounding option. That means whether we want to round towards even number or to the number away from zero.
For example, when someone do the rounding of 8.5 . MidpointRounding will help to specify whether rounding will be towards the even number (8) or it will be away from zero (9).
http://www.mindfiresolutions.com/MidPointRounding-for-MathRound-method-in-Net-Application-293.php[^]
Cheers,
Eliza
|
|
|
|
|
Wrong forum, this forum is for code that is soo ugly, its own momma vomits when she looks at it.
Your post would be better in "Tips and Tricks".
Dalek Dave: There are many words that some find offensive, Homosexuality, Alcoholism, Religion, Visual Basic, Manchester United, Butter.
Pete o'Hanlon: If it wasn't insulting tools, I'd say you were dumber than a bag of spanners.
|
|
|
|
|
|
Not really relevant to this forum, but it has caught my attention.
Are these really the only two options for rounding in .NET? What if I want (for example) to always round up (i.e. 1.5 becomes 2, but -1.5 becomes -1). That sounds a bit odd at first, but in some banking applications I have worked on that was how it worked because you rounded in the bank's favour. (Banks never miss a trick when it comes to money.)
|
|
|
|
|
Use the Math.Ceiling(1.5) = 2, Math.Ceiling(1.0001) = 2
Math.Ceiling(-1.5) = -1, Math.Ceiling(-1.99999) = -1
...
Is what you are looking for?
PS: If it is, I'll start hiding my savings under my bed
|
|
|
|
|
Well I was thinking more in terms of being able to say something like MidPointRounding.Up, or something like that. I'm basically lazy and prefer to rely on other people to do the grunt work and write the boring little stuff.
It comes into things like currency trading for example. If the bank is calculating the rate at which they want to sell you something (dollars, for example) and they need to round it to a certain number of decimals, they will round it in such a way that is favourable to them. It may be a small thing on each trade, but it adds up.
When they are doing things like calculating interest payments, they use "traditional" rounding.
|
|
|
|
|
Please tell which banks these were for so I can bank elsewhere!
|
|
|
|
|
Not a horror by any means.
(unless you have roundophobia, I guess)
|
|
|
|
|
This is the structure for a MySQL table some anonymous guys from 6ib at the Koninklijk Atheneum Sint-Niklaas[^] created. It's in Dutch, but I'm guessing you'll get the point anyway. The table is supposed to store answers from an enquite.
CREATE TABLE IF NOT EXISTS `antwoorden` (
`id` int(11) NOT NULL auto_increment,
`geslacht` text NOT NULL,
`studeren` text NOT NULL,
`geboorteJaar` int(4) NOT NULL default '0',
`gsm` text NOT NULL,
`prijsGsmToestel` text,
`herlaadmanier` text,
`provider` text,
`bedragPerMaan` text,
`smsPerDag` text,
`belPerDag` text,
`mp3` text NOT NULL,
`prijsMp3` text,
`gebruikMp3` text,
`pc` text NOT NULL,
`aantalPc1` text,
`aantalPc2` text,
`aantalPc3` text,
`aantalPc4` text,
`aantalPc5` text,
`aantalPc6` text,
`aantalPc7` text,
`aantalPc8` text,
`aantalPc9` text,
`aantalPc10` text,
`prijsPc` text,
`pcWerk` text,
`pcSchool` text,
`pcGamen` text,
`pcFilm` text,
`pcComm` text,
`pcSociaal` text,
`pcMuziek` text,
`pcAndere` text,
`pcGebruik` text,
`pcProvider` text,
`pc2000` text,
`pcXp` text,
`pcVista` text,
`pc7` text,
`pcLeo` text,
`pcSnowLeo` text,
`pcLinux` text,
`pcUnix` text,
`pcAndereBest` text,
`pda` text NOT NULL,
`prijsPda` text,
`pdaWerk` text,
`pdaSchool` text,
`pdaGamen` text,
`pdaAndere` text,
`pdaGebruik` text,
`pdaProvider` text,
`tv` text NOT NULL,
`tvGebruik` text,
`tvProvider` text,
`gamen` text NOT NULL,
`play1` text,
`play2` text,
`play3` text,
`xbox` text,
`xbox360` text,
`psp` text,
`pspGo` text,
`gameCube` text,
`wii` text,
`ds` text,
`gameAndere` text,
`consoleAantal` text,
`prijsGames` text,
`digiFoto` text,
`filmCamera` text,
`extHD` text,
`memStick` text,
`videoRec` text,
`dvdSpelRec` text,
`bluRay` text,
`dlToetsMuis` text,
`gameToeb` text,
`surround` text,
`printer` text,
`webcam` text,
`scanner` text,
`enqueteLeuk` text NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;
I think this is just brilliant and the authors should be nominated form the Nobel prize.
EDIT: Check out my blog post[^] about this
Jeroen De Dauw
---
Forums ; Blog ; Wiki
---
70 72 6F 67 72 61 6D 6D 69 6E 67 20 34 20 6C 69 66 65!
modified on Monday, March 22, 2010 8:35 PM
|
|
|
|
|
I do not know the Dutch for "What a load of Crap", but I think you get the gist.
Seriously, we should have a whip round and send them a Databases For Dummies right away.
------------------------------------
I will never again mention that I was the poster of the One Millionth Lounge Post, nor that it was complete drivel. Dalek Dave
|
|
|
|
|
I was in Sint-Niklaas only yesterday, as a tourist. Little did I know they actually have software professionals there, I could have set up a meeting and learn something new.
|
|
|
|
|
Tss, I wouldn't nominate them for the Nobel prize... If they can type all of this but forget the last 'd' in the field bedragPerMaan they're not worth it
|
|
|
|
|
Very nice! With "AUTO_INCREMENT=3" they leave even some "empty" lines in between - what will they do with them?
Another guess is that they want to do some data mining, because there you normally remove all normalization. Maybe these guys were a bit smarter than we'd expect from the first view of their table design.
|
|
|
|
|
"If you only knew the magnificence
of the 3, 6 and 9, then you?
would have a key to the universe."
— Nikola Tesla
Maybe this guy is a genius too.
|
|
|
|
|
bhiller wrote: With "AUTO_INCREMENT=3" they leave even some "empty" lines in between
In MySQL, the AUTO_INCREMENT keyword on a table specifies the initial value for the first insert, not the increment size.
|
|
|
|
|
To quote Ray Stanz from Ghostbusters: "The guy who designed this was either a certified genius or an authentic wacko." But, he wasn't a genius though.
Dalek Dave: There are many words that some find offensive, Homosexuality, Alcoholism, Religion, Visual Basic, Manchester United, Butter.
Pete o'Hanlon: If it wasn't insulting tools, I'd say you were dumber than a bag of spanners.
|
|
|
|
|
Not speaking Dutch, I can't be sure, but I think the author has forgotten a column for right-hand or left-hand use.
Chris Meech
I am Canadian. [heard in a local bar]
In theory there is no difference between theory and practice. In practice there is. [Yogi Berra]
|
|
|
|
|
O M G !!!!
Aside from the fact that it is a massive table of text.....WHY WHY WHY WHY WHY do people design G.D. databases with an incremental ID as the mother fracking key!!!!! AHHHHHH I want to shoot that designer.
[deep breath...pause... nope I still want to shoot the designer]
[Buddhist chants...meditation...an hour of tai chi....hmmm nope I still want to shoot the designer]
Oh well.
|
|
|
|
|
LongRangeShooter wrote: WHY do people design G.D. databases with an incremental ID as the mother fracking key
I'm not sure what you mean by "incremental ID" here. Do you mean auto-incrementing?
|
|
|
|
|
LongRangeShooter wrote: WHY WHY WHY WHY WHY do people design G.D. databases with an incremental ID as the mother fracking key
This bugs me too, sometime you find that such people grew writing VBA apps on Accees, which natually makes them database designers . Occaisionally technology "forces" it see: http://en.wikipedia.org/wiki/Surrogate_key#Compatibility[^] Genuinely, I blame lack of training as people often grow up hacking databases together, istead of understanding the theory behind them.
To me, surrogate keys are a sign of bad normalisation, can lead to duplicates more easily, and increases the likelyhood of bad join conditions. I'm fascinated by the internicene warfare around relational database design, as these directly correlate to set theory and therefore we should largely agree about the principles at least. I mooted this point in the C# forum and got an immediate long rant informing me how a properly normalised database is too hard to use, I didn't even argue back as the guy was obviously too stupid to bother with.
I worked in a company that collapsed because they bought a 3rd party software. The vendor pitched it "We handle all the information checking in code [i.e. referential integrity, duplication protection, orphaning protection etc], so our system is more flexible. Net result: Orphaned records, lost records, duplicate jobs, all because it is "too difficult" to normalize.
Dalek Dave: There are many words that some find offensive, Homosexuality, Alcoholism, Religion, Visual Basic, Manchester United, Butter.
Pete o'Hanlon: If it wasn't insulting tools, I'd say you were dumber than a bag of spanners.
|
|
|
|
|
jeroen de dauw wrote: EDIT: Check out my blog post[^] about this
Dude. Who told you that black text on a dark grey background made for a good, READABLE, website?
|
|
|
|
|
Dark Gray background? What browser are you using?!!
Jeroen De Dauw
--- Forums ; Blog ; Wiki---
70 72 6F 67 72 61 6D 6D 69 6E 67 20 34 20 6C 69 66 65!
|
|
|
|
|
Wow. IE7 at work.
I fired up IE7 at home and it looks OK now. Back at work, it was all dark gray, except for the code snippets.
|
|
|
|
|
I can second that. I am using IE7 and it's a grey background, black text. Very hard to read. The code snippets show up OK, with a white background.
EDIT:
Just tried it in FF3 and it's a white background. In IE7 there is a background image showing which is sort of a dark greyish colour. In FF3 that image is not displayed, so you only see the default browser back colour (i.e. a plain white background). It looks like some problem with the CSS file that defines the class for the box where you are showing your text. IE likes it, FF doesn't.
Welcome to the world of cross-browser support.
|
|
|
|
|
FF3.0: OK
IE7: bad
|
|
|
|
|