Please guide me an issue, I am getting a price from the server as below (as an example)
two hundred forty-two
and I want to convert this value into 242.00.
Please guide me on how to convert it.
I know we can use .spellOut with NumberFormatter for converting value into String but can't find a way to do the above.
Alright, you have managed to nerd-snipe me.
I've implemented a number string parser as a Swift package. I don't expect you to bring in a whole package just to do this, but you might find some inspiration here:
https://github.com/daltonclaybrook/NumberParser
Related
I'm working with long integers in dart and want to know how to add a comma after every three numbers.
Example;
999999999 would turn into 999,999,999
I get this information from an online API, so I can't change the int from a local file and follow that pattern, I need to intercept the int before/as it's being displayed.
Thanks
After looking at this stack question I found a way to accomplish this if your variable is a string.
This is what that looks like;
import 'package:intl/intl.dart';
final oCcy = new NumberFormat("#,##0.00", "en_US");
"${oCcy.format(yourVar)}",
Despite this, I was actually dealing with an integer, so using this method left me with an error. This was easily fixed by converting the string into an int.
This is what that looks like;
"${oCcy.format(double.parse(yourVar))}",
Is there any way to convert ISO 4217 numeric code to currency code like this:
978 -> EUR
I checked Apple docs and I found only how can I take EUR
Here is what I searched:
Locale
Locale spesific
There is no API available in iOS (or any other Apple OS) that provides information about ISO 4217 codes. You will need to create your own mapping.
I would find a definitive list of codes (perhaps Wikipedia or the ISO website) and put the codes in a plist file. Then write a simple Locale extension that lets you get a currency code from a 4217 code.
As rmaddy suggested I made a plist with iso4217 codes and did my own mapping, here is the playground for anyone who wants it.
I've been using Youtube API v3 (yes, I know, it wasn't meant for Lua) recently, but when I need to convert an ISO 8601 duration into a formatted string, nothing on the web helps. I've been googling all over the place, to search for a specific library that could help with this sort of thing, but unfortunately, there is NONE for Lua. There is thousands of libraries out there for other languages except Lua.
And now, it seems I'm stuck with string patterns which I don't even know how to use. So how else would I go about doing this task?
Example of an ISO 8601 duration:
PT3M33S
I want to convert it into something like this:
3:33
If you don't want to parse the whole ISO 8601 specification, try this code:
s="PT3M33S"
t=s:gsub("^.-(%d+)M(%d+)S","%1:%2")
print(t)
It uses Lua pattern matching. The pattern reads: skip everything until a run of digits followed by an M and then find a run of digits followed by an S. Capture both runs of digits and use them in the replacement pattern.
If you want to extract both numbers, use this:
s="PT3M33S"
M,S=s:match("^.-(%d+)M(%d+)S")
print(M,S)
I'm running into a search issue with my question. I'm trying to link an actual dictionary (e.g., words with definitions) to some code I'm writing in F#. Specifically, I'm using FsVerbalExpressions to identify whitespace-separated strings and would like to look each string up in an actual dictionary to determine if they're words or not.
The problem I'm having is that when I search on SO (or Google or anywhere else) for "link dictionary to F#" or "F# dictionary library" or some other permutation of "F#" and "dictionary," I get hits on how to use the dictionary collection in F#.
I'm hoping someone out there has some insight into how to link a dictionary, though this answer has given me some directions to alternatives if I can't find exactly what I'm trying to do.
Thanks for your help!
If you're used Cocoa for a while you're probably familiar with NSDateFormatter
and NSNumberFormatter. They're handy for creating formatted display strings from dates and numbers, or for converting date or number strings into numeric values, while supporting different languages and locales.
A few weeks ago I stumbled on NSDateComponentsFormatter, which lets you create formatted time intervals like "4 hours, 37 minutes and 17 seconds." Pretty cool.
There's also the related NSDateIntervalFormatter, which creates strings by comparing 2 dates.
Then there are some REALLY obscure NSFormatter subclasses:
NSMassFormatter
NSByteCountFormatter
NSLengthFormatter
NSEnergyFormatter
NSPersonNameComponentsFormatter
EDIT:
From the comments, I've aded NSPersonNameComponentsFormatter.
Searching on "NS*Formatter" in the Xcode help system reveals most of these, but not all. (It looks like the help text has to be indexed correctly in order for searching to work, which is annoying.)
That brings the total I have been able to find to
NSDateIntervalFormatter -Difference between 2 dates
NSDateComponentsFormatter -NSDateComponents to/from string
NSDateFormatter -Formats NSDates as strings
NSNumberFormatter -Formats numbers as strings
NSMassFormatter -Formats mass quantity as strings
NSByteCountFormatter -Formats byte counts in K, MB, GB, etc.
NSLengthFormatter -Formats length values
NSEnergyFormatter -Displays energy qualities in Joules or Calories
NSPersonNameComponentsFormatter - displays localized formatted names
Annoyingly, it looks like many of these formatters don't have a locale property, so it's not very easy to use them to create formatted strings in languages/locales other than the system's default locale. If I'm missing something, please tell me.
Does anybody else know of other formatters I'm missing? These are pretty obscure, but could save you a lot of time if you were to need them.
EDIT #2:
Question part 2: Is there a way to get output from the formatters that lack a locale property in locale's other than the system default locale? It seems silly that they don't ALL have and honor a locale property. It's pretty common to need to generate output for languages/locales other than the current locale.
There's no need to search. The NSFormatter documentation lists all of its subclasses. Look at the top of the page, in the "inherits from" block.
Note that this information is not available in the Xcode 7.3 doc reader. It's only available in the online docs (or by using the excellent Dash reader).
I went into
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/System/Library/Frameworks
and then did
for header in **/*.h; do ack -o 'NSFormatter' "$header"; done
which gave me some interesting ones:
NSPersonNameComponentsFormatter
CNContactFormatter
CNPostalAddressFormatter
DRMSFFormatter
MKDistanceFormatter
Doing the same for iPhoneOS.sdk didn't turn up any new NSFormatter subclasses.