We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

getStringValueWithoutFormat returns Decimal instead of Integer

we use this neat method to read a value without any Format for further process

https://apireference.aspose.com/cells/java/com.aspose.cells/cell#StringValueWithoutFormat

unfortunately in one case it returns a decimal instead of an integer

Excel cell value is

16500

as of xml in within the excel <c r="A1"><v>16500</v></c>

nevertheless it returns

 cell.getStringValueWithoutFormat()
 (java.lang.String) 16500.0

why does it not return 16500 instead of 16500.0 ?

@rbi-sw-dev,
We will analyze this issue and share our feedback soon.

@rbi-sw-dev,

Please try using cell.getStringValue() or cell.getIntValue(), it will work for your needs.

unfortunately this won’t help, as we read customizable fields from excel sheets, I never know what I get, that’s why we use getStringValueWithoutFormat() because this gives us in every case (except the one mentioned above) the correct value of the pure field without format

in our case for example when there comes a formatted value of 16.500 (which means 16500) we need 16500
getIntValue() I cannot use, because, we also read values with decimal values like 4077,42

@rbi-sw-dev,

As we already noticed the issue, so I have logged a ticket with an id “CELLSJAVA-43246” for your issue. We will investigate and look into it soon.

Once have an update on it, we will let you know.

1 Like

@rbi-sw-dev,
For performance consideration, commonly we do not check whether one numeric value can be converted to an integer.

For your requirement, the common solution should be that you check value type of the cell, if it is NUMERIC or DATETIME, then you can use Cell.getDoubleValue() to get the numeric value and check whether it can be taken as Integer.

we already check the value for it’s type, but this does not help me, I want the

cell.getStringValueWithoutFormat()

of the cell this should give me 16500 and not 16500.0 this is just wrong, you don’t need to check if it is integer or not I just want the string representation of the value of the excel sheet in the xml

@rbi-sw-dev,

The ticket is closed with “Won’t Fix” label. We cannot fix the issue due to performance grounds.
As we already told you, generally, Aspose.Cells does not check whether one numeric value can be converted to an integer or not due to performance. For your needs, the possible solution should be: you may check value type of the given cell whether it is NUMERIC or DATETIME type. Now you can use Cell.getDoubleValue() to get the numeric value and then you may use your own code to to get your desired integer value part (before “.”) accordingly.

thanks for the information but why i would have to check it for a type, i want the string value of the field (without format) and this is 16500 and not 16500.0 !!!

furthermore this method is even more wrong when I want to read a value of 00042
I would expect it return 00042, but get 42 as “StringValue without Format” (when i want the STRING VALUE of this field without any format)
like getStringValue would give me, unfortunatelly there i get the format

i want just the string value !!! without format!!!

@rbi-sw-dev,

Aspose.Cells process numeric values in double to give best performance.

Anyways, to give you more clarifications we will get back to you soon with more details. Please stay tuned.

@rbi-sw-dev,

Please note, Cell.StringValueWithoutFormat was originally provided for some special purpose according to some users’ requirements. It is not designed as "returning the string expression stored in the XML of the template file”. Instead, this property just gives the simple string representation of the internal object in our data object model. And, this property is not only used for those cells loaded from template files of ooxml format. For other file formats, there is no such kind of XML and then no such kind of string representation in the XML. Even for those string representation values, such as in ooxml, csv, html…etc., we don’t keep one copy of the representation in our model, so it is not always feasible to get the original string representation for a cell.

For your requirement, we don’t think this property is suitable as this property is not designed for such kind of requirements. As we have said, you have to check cell’s type and then build the proper string representation by yourself according to your requirements.

Thanks for your understanding!

thanks for the explanation, we will write a workaround to the function…
cell.getStringValue() get us the real string (unfortunately also the format of excel)

so we’ll use for Excel - in case of CellValueType.IS_NUMERIC getStringValueWithoutFormat() and cut the .0 away as it is not possible to store .0 in Excel Number Fields and for CSV getStringValue() for numeric accounts like 000842 to get also 000842 and not just 842 when the value starts with 0

not pretty but yeah… so long

@rbi-sw-dev,
Your approach seems ok and feel free to contact us incase of any issue or query.

One more concern is if user input a number with more digits (i.e. 11231123) and you will get a string with E (i.e. 1.1231123E7) by getStringValueWithoutFormat(). May I ask for the reason of no function returning the original input or did I miss anything?

1 Like

@KtkWong198512,

Give your sample code (runnable) and attach your template file (you may zip the file prior attaching), we will check it soon.

that we also noticed, that’s why we convert it in BigDecimal() and then in string again…

String value = new BigDecimal(cell.getStringValueWithoutFormat()).toPlainString();

but agreed, would be nice if the method does not do conversions and just return the same value as getStringValue (just without format)

1 Like

As we have told you, this property is defined for some users’ special requirements and there are constrains for using it. We are sorry but we cannot change it for your custom requirements which may break existing applications of other users. In fact and it looks this API may cause confusion for more and more users, so we might mark it as obsolete and can be replaced by other APIs later on.

Currently you have to use Cell.Type and Cell.Value to check and operate on the cell values and build the results you expect by yourselves, especially for numeric values.

As we understand your concerns, nevertheless we rely on the method “getStringValueWithoutFormat”, because for the reasons above, we wrote 3 workarounds around it but we need this method, because of getStringValue (includes the format), getDouble give me a double and not the correct number!

and nevertheless for the future it would be nice to have a getStringValueWithoutFormatAndWithoutFormattingForReal() :wink: :slight_smile:

We are afraid even your recommended APIs are still ambiguous. What’s the “real” value? In fact the object we returned for Cell.Value is the real value (for a workbook loaded from the template file, it may be the value saved in the template file) but it seems the object itself does not fit your requirements. There are too many scenarios for different users to use the cell value, so we are afraid we cannot make the APIs fit for all users’ requirements. However, you should be able to get what you want by Cell.Value object. For example, truncate double value to 15-digits, just as what is shown in MS Excel with number format of full digits.