Dart - Adding a recurring character to an integer - dart

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))}",

Related

FME change data format from string to numeric

Struggling with a really simple problem; I need to convert attribute from string to numeric in FME. have tried using the arithmetic editor, but every time I export to GIS I get string. It seems when one uses the statistics calculator you get numeric.
Any ideas? As I am all out of them.
Ashton

Convert double 15,34 to 15.34

I'm trying to get a json string but I noticed that when I pass some double numbers to my query the integer part is separated by a coma from the floating part. I need them to be separated by a point. Is this connected to the Language of the os?
You can use a simple regex to fix this issue:
\d+,\d+ to select the offending bits of JSON, and a string-based replace on the results. If you already have the numbers separated out, use the replace function (something like val.replace(",",".")) on the value you have, and cast it to a float (float(val) in Python).

How to read a string for a number starting with a decimal point in Haskell?

I'm a total Haskell beginner who just discovered that read spits out an exception when given a decimal number starting with . rather than a digit. For example, in ghci:
Prelude> read ".7" :: Float
*** Exception: Prelude.read: no parse
I found one discussion and it makes sense why surrounding . in numbers with digits is required in Haskell. Another discussion is also somewhat helpful, but no one provides a solution of how to actually convert ".7" to 0.7.
So, I'm trying to extract data from a fixed-width format file containing fields with values like .7---is there a standard function or approach I can use to clean this up to a float 0.7?
(Before I hit this issue, my basic ideas was to define a custom type for my data, use splitWidth in Data.List.Split to split each line into its fields, and then use read to convert each field into its correct type, trying to apply the functional goodness in this answer in the actual implementation.)
As Thomas M. DuBuisson answered in a comment above, the obvious thing to do is myRead = read . ('0':) :: String -> Float. This works for me --- I won't ever be trying to read negative numbers, and I know which fields should be read as float. Thanks!

How do I avoid errors when converting strings to numbers if I don't know whether I have floats or integers?

I have stringgrid on delphi form and i am trying to divide values of one cell with value of another cell in another column.
But the problem is, stringgrid cells are populated with different types of numbers, so I am getting ConvertErrors.
For example the numbers in cells can look like
0.37 or 34 or 0.0013 or 0.00 or 0.35 or 30.65 or 45.9108 or 0.0307 or 6854.93.
In another words I never know is it going to be real, float, integer or any other kind of type in those cells.
I have looked everywhere on internet but no luck. Anyone any ideas. By the way I am not exactly Delphi expert. Thanks.
For each string, convert it first to a float value using StrToFloat function in SysUtils.pas . This should allow for any numerical type to be dealt with (unless you have something unusual like complex numbers). As you have some zero values in your list above you should also ensure that you check for divide by zero conditions as this will also potentially throw an exception.
SysUtils has many functions such as TryStrToFloat, TryStrToInt, TryStrToInt64 etc for this purpose. These functions accept a reference parameter (var parameter) for returning the converted value and function itself returns true if the conversion is successful.
If you are sure that the string has a valid number then you can check the input string to see if it has a decimal point before deciding which function to use.
Treat all the numbers as float. Use StrToFloat, divide the numbers, and then convert the result back to string with FloatToStr. If the result is an integer, no decimal point would be produced.

Character #\u009C cannot be represented in the character set CHARSET:CP1252 - how to fix it

As already pointed out in the topic, I got the following error:
Character #\u009C cannot be represented in the character set CHARSET:CP1252
trying to print out a string given back by drakma:http-request, as far as I understand the error-code the problem is that the windows-encoding (CP1252) does not support this character.
Therefore to be able to process it, I might/must convert the whole string.
My question is what package/library does support converting strings to certain character-sets efficiently?
An alike question is this one, but just ignoring the error would not help in my case.
Drakma already does the job of "converting strings": after all, when it reads from some random webserver, it just gets a stream of bytes. It then has to convert that to a lisp string. You probably want to bind *drakma-default-external-format* to something else, although I can't remember off-hand what the allowable values are. Maybe something like :utf-8?

Resources