Money data type for .NET?
Martin Fowler considers money as a special case of “Quantity”, secondly he thinks the right Data Type for money should be the Big Integer. And he does have a point. Quantity and Money Pattern by Martin Fowler
Martin Fowler considers money as a special case of “Quantity”, secondly he thinks the right Data Type for money should be the Big Integer. And he does have a point. Quantity and Money Pattern by Martin Fowler
You could use a regexp: var regex = /^\d+(?:\.\d{0,2})$/; var numStr = “123.20”; if (regex.test(numStr)) alert(“Number is valid”); If you’re not looking to be as strict with the decimal places you might find it easier to use the unary (+) operator to cast to a number to check it’s validity: var numStr = “123.20”; var … Read more
Use this code. Here is a working example http://plnkr.co/edit/xnN1HnJtTel6WA24GttR?p=preview {{num | currency:’USD’:true:’1.2-2′}} Explanation : number_expression | number[:digitInfo] Finally we get a decimal number as text. Find the description. number_expression: An angular expression that will give output a number. number : A pipe keyword that is used with pipe operator. digitInfo : It defines number format. … Read more
I don’t know if it’s the best solution, but what I’m trying now is to just pass values as strings unformatted except for a decimal point, like so: “amount”: “1234.56” The app could easily parse that (and convert it to double, BigDecimal, int, or whatever method the app developer feels best for floating-point arithmetic). The … Read more
You probably want something like this (assuming currency is a float): NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init]; [numberFormatter setNumberStyle: NSNumberFormatterCurrencyStyle]; NSString *numberAsString = [numberFormatter stringFromNumber:[NSNumber numberWithFloat:currency]]; From your requirements to treat 52 as .52 you may need to divide by 100.0. The nice thing about this approach is that it will respect the current locale. … Read more
Here is a simple function to do it: function abbrNum(number, decPlaces) { // 2 decimal places => 100, 3 => 1000, etc decPlaces = Math.pow(10,decPlaces); // Enumerate number abbreviations var abbrev = [ “k”, “m”, “b”, “t” ]; // Go through the array backwards, so we do the largest first for (var i=abbrev.length-1; i>=0; i–) … Read more
From the research that I’ve done, there doesn’t appear to be any documentation available for the API you’re using. Depending on the data you’re trying to get, I’d recommend using Yahoo’s YQL API for accessing Yahoo Finance (An example can be found here). Alternatively, you could try using this well documented way to get CSV … Read more
A bit late but this is a solution I used to get the $ instead of US$ etc. for currency symbol. /* * Bear in mind not every currency have a corresponding symbol. * * EXAMPLE TABLE * * currency code | Country & Currency | Currency Symbol * * BGN | Bulgarian lev | … Read more
The RegEx // Requires a decimal and commas ^\$?(([1-9]\d{0,2}(,\d{3})*)|0)?\.\d{1,2}$ // Allows a decimal, requires commas (?=.*\d)^\$?(([1-9]\d{0,2}(,\d{3})*)|0)?(\.\d{1,2})?$ // Decimal and commas optional (?=.*?\d)^\$?(([1-9]\d{0,2}(,\d{3})*)|\d+)?(\.\d{1,2})?$ // Decimals required, commas optional ^\$?(([1-9]\d{0,2}(,\d{3})*)|0)?\.\d{1,2}$ // *Requires/allows X here also implies “used correctly” The RegEx Breakdown When the optional parts are too liberal, we need to look ahead and guarantee there’s a … Read more
I would just create a couple methods; int RoundUp(int toRound) { if (toRound % 10 == 0) return toRound; return (10 – toRound % 10) + toRound; } int RoundDown(int toRound) { return toRound – toRound % 10; } Modulus gives us the remainder, in the case of rounding up 10 – r takes you … Read more