In my data set there is a field that is currently a character field and I need to convert it to a numeric one. the problem is not only are there '%' signs hard coded in the data but there are decimal points in there as well and places after the decimal points is not consistent. AKA...
42.01%
8.1%
22%
.05%
I substringed off the % sign but is there a way to just cut the decimal point off and everything after it so then I can just cast it as an integer?
thanks all
Cut % then convert to double. Then apply ceiling function.
What I had to do was put leading 0's on the front of the element because cognos was not reading the entries that started with decimal places. then I had to substring the % off and trim and then cast as a number.
Related
I have a data frame with a column full of 13-digit numbers. But there is a mistake there, there had to be a decimal point before the last 3 digits (e.g., the number 1582305791901 should have been 1582305791.901).
So I thought I could easily solve this problem by simply dividing the entire column by 1000. But this does not preserve the decimal points, instead I get 1582305791. How can I solve this? (P.S. The column is of type "numeric", not "integer".)
Thank you!
try running this option first
options(digits = 15)
check if your number is stored as integer with typeof and class, then as.numeric(x)/1000
I am Using RDLC Expression for rounding of my data to 4 decimals. but if i use 'Round' function it will show zeros after decimal point if the data has no decimal values.
Ex: If my value is 1 it shows 1.0000.
How to remove zeros?
My Expression: =Round(CDec(Fields!ExchangeRate.Value),4)
I need number without decimal point as whole number, if it has decimal values then it should display with decimal values.
Thanks in Advance.
=Format(CDec(Fields!ExchangeRate.Value),"#.####")
Above Expression Works fine. Thank You.
Simply try this...it works for me.
you can use the Format property of the textbox as
1- right click the textbox
2- click number
3- select Number from the category
4- set Decimal Places to 0
hope it will help you
regards
I am making an editor for a field with numbers. I tried a text field, but since it's a Number datatype coming in, it didn't go smoothly -- despite recasting strings as numbers etc.. it kept giving me NaN as the value. So I decided it would be best to go with a numeric stepper.
When I initially loaded it up it would drop all my decimals and only display my numbers as integers. I changed the stepIncrement to 0.1 and now it does show the decimals (a weird requirement imo).. but when I step up it occasionally gives me a value like '17.700000000000003' when I would expect 17.7. All of the numbers in my data have a single decimal place. I know I can write a dataformatter, but it seems like it shouldn't be necessary in this situation.
Is there another way I could deal with this?
You've stumbled upon the compromise of trying to represent decimal numbers in floating point binary formats like IEEE 754. Not all decimal numbers can be exactly represented. You can read up on this issue in great detail here:
http://en.wikipedia.org/wiki/Floating_point#Representable_numbers.2C_conversion_and_rounding
You can use Number.toFixed(fractionDigits:uint) to display to an arbitrary number of decimal places.
You can use the valueFormatFunction which takes the numeric value and formats it to a string. You will need to set explicit widths on your numeric steppers to make they fit though.
in your MXML
<s:NumericStepper valueFormatFunction="stepperFormatter"/>
in your script
protected function stepperFormatter(newValue:Number):String
{
return Math.ceil(newValue).toString()
}
Just a quick one here, does anyone know of a good regular expression for a percentage? Including 2 decimal places, i.e. 15.22%. I'm looking to put it inside a regularexpressionvalidator in ASP.NET.
This accepts 0.00%-100.00% including any number of leading zeros:
^0*(100\.00|[0-9]?[0-9]\.[0-9]{2})%$
(\d+(\.\d+)?%)
That should work.
\d\d\.\d\d%
To make the decimal portion optional:
\d\d(\.\d\d)?%
If single digit values are not padded with zeros:
\d{1,2}(\.\d\d)?%
Finally, to allow 100%
(100|\d{1,2}(\.\d\d)?)%
Updated to reflect #Lucero's input:
Forcing 2 decimals
^[0-9]+\.[0-9]{2}%$
Allowing either 2 decimals (with decimal) or integer. Both followed by percent.
^[0-9]+(\.[0-9]{2})?%$
I have a SQLite3 table with a column having format DECIMAL(7,2), but whenever I select rows with values not having a non-zero 2nd decimal place (eg. 3.00 or 3.10), the result always has trailing zero(s) missing (eg. 3 or 3.1). Is there any way that I can apply a formatting function in the SELECT statement so that I get the required 2dp? I have tried ROUND(), but this has no effect. Otherwise I have to keep converting the resulting column values into the required format for display (using Python in my case) every time I do a SELECT statement, which is a real pain.
I don't even mind if the result is string instead of numeric, as long as it has the right number of decimal places.
Any help would be appreciated.
Alan
SQLite internally uses IEEE binary floating point arithmetic, which truly does not lend itself well to maintaining a particular number of decimals. To get that type of decimal handling would require one of:
Fixed point math, or
IEEE decimal floating point (rather uncommon), or
Handling everything as strings.
Formatting the values (converting from floating point to string) after extraction is the simplest way to implement things. You could even hide that inside some sort of wrapper so that the rest of the code doesn't have to deal with the consequences. But if you're going to do arithmetic on the value afterwards then you're better off not formatting and instead working with the value as returned by the query, because the format and reconvert back to binary floating point (which Python uses, just like the vast majority of other modern languages) loses lots of information in the reduced precision.