SharePoint - what type is Number field - sharepoint

I have a Field, that has Type="Number". What type of variables can I assign to it?
Will the field support float or double?
oListItem["numberField"] = data;
What type can data be?

All values that's string representation can be parsed as double, since SharePoint converts the input value to a string:
case SPFieldType.Number:
case SPFieldType.Currency:
str1 = Convert.ToString(value, (IFormatProvider) CultureInfo.InvariantCulture);
break;
(from SPListItem.SetValue(...))
You should be fine with string, int, double, etc.

Related

How to use type Number or Array in GraphQL typedefs

I'm trying to use type Number and type Array in my typedefs for a Product type in GraphQL. But GraphQL gives me some errors in the console. It's my first time using GraphQL though.
Unknown type "Array".
Unknown type "Number".
Here's the typedef I'm trying to create.
type Product {
sku: String
productName: String
isNewProduct: Boolean
isPromo: Boolean
promoType: String
promoPrice: Number
promoStart: String
promoEnd: String
stockingPrice: Number
finalPrice: Number
isActiveProduct: Boolean
availableQuantity: Number
quantityUnit: String
category: String
saleType: String
manufactureCompany: String
year: String
color: String
tags: Array
variantID: String
description: String
}
I checked around and saw that there are type ID and type Float in the case for numbers.
But, I'm writing JavaScript. There's a possibility that the promoPrice property will be getting either a float or an int and I don't want an error thrown if that's the case. That's why I want to use type Number.
Also, what do I do in the case for arrays containing both strings and numbers?
The GraphQL schema language supports the scalar types of String, Int, Float, Boolean, and ID.
Use Int if you want to use Number. If your tags are Array of Strings then You could actually define like tags: [String]

How can string be converted to number in xceptor

What enrichment/formula is required to convert a string to number in Xceptor. I tried FormatNumber
You would need to add a calculation enrichment and then use the DECIMAL([string field]) function - description for this is - DECIMAL: Converts a text string to a decimal.
You can use the INTEGER function to convert a string to an integer
For example, TestInteger = INTEGER("7600")
More information can be found here Xceptor Docs - INTEGER Function

Groovy : String to float Conversion

Used code below to save value for float
domainInstance.standardScore = params["standardScore"] as float
In this case my input was given as 17.9 and in db2 database saving as 17.899999618530273 but I want to save as 17.9 itself, let me know how to do it
You can't set precision to a Float or Double in Java. You need to use BigDecimal.
domainInstance.standardScore = new BigDecimal(params["standardScore"]).setScale(1, BigDecimal.ROUND_HALF_UP);
The method BigDecimal.setScale(1, ...) limits decimal to one place only. The second parameter is the rounding strategy.
You need to use BigDecimal to do Conversion from String, then BigDecimal(value).floatValue() to get float, You can do this on more that one way, examples
1 - Using setScale in BigDecimal
def temp = new BigDecimal(params["standardScore"]).setScale(1, BigDecimal.ROUND_HALF_UP)
2- Using DecimalFormat
DecimalFormat df = new DecimalFormat("#.0");
def temp = new BigDecimal(df.format(params["standardScore"] ))
Then you need to get the float value
domainInstance.standardScore = temp.floatValue()

Converting String into Primitive Types in java...Possible?

I want to know that is it possible to convert String into char, int,float,double and other primitive types
If yes then How.. If no then why..we can't do it.
In primitive type we can convert any primitive into any other using Type Casting..so Is there Something to do so with the Strings. As we know that we can convert any primitive type into String ,so is it possible to convert String into Primitive types..
Of course it is possible in java. As you know String is a class in java. this String class defines a method toCharArray() which is used to convert a String object to character array. Its return type is array of characters.
String str = "java";
char arr[];
arr = str.toCharArray();
Just use:
String str = "myString";
char[] charArray = str.toCharArray();
Finally found some really easy and working way..to convert String into Primitive Types...
We Can use wrapper class for conversion
But we have pay extra attention converting String into Primitive Types because we can only convert String into the requires primitive type if primitive type actually supports the data....i.e we can't convert a String into int if it's no(0 to 9),
any other data will throw runtime exception...Same will be applied to all other Primitive Types
//String to primitive types
int iVal = Integer.parseInt(str);
long lVal = Long.parseLong(str);
float fVal = Float.parseFloat(str);
double dVal = Double.parseDouble(str);

How to convert string to integer in Javascript(Rhino) Programming Language?

I have one variable which contains integer values in string format as given below:
strValue = "123"
I want to convert this string value to integer type so it will be helpful for mathematical operation.
How can I do that in Javascript(Rhino) Language?
You can use the parseInt function that recieves a string and returns int.
Example:
var string = "123"
var number = parseInt(string)
print(number * 2)

Resources