Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docs: document apostrophe as an explicit string literal trigger #1334

Merged
merged 8 commits into from
Dec 19, 2023
12 changes: 6 additions & 6 deletions docs/guide/advanced-usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,9 @@ console.log(winningTeam)
## Demo

<iframe
src="https://codesandbox.io/embed/github/handsontable/hyperformula-demos/tree/2.6.x/advanced-usage?autoresize=1&fontsize=11&hidenavigation=1&theme=light&view=preview"
style="width:100%; height:500px; border:0; border-radius: 4px; overflow:hidden;"
title="handsontable/hyperformula-demos: advanced-usage"
allow="accelerometer; ambient-light-sensor; camera; encrypted-media; geolocation; gyroscope; hid; microphone; midi; payment; usb; vr; xr-spatial-tracking"
sandbox="allow-autoplay allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts"
></iframe>
src="https://codesandbox.io/embed/github/handsontable/hyperformula-demos/tree/2.6.x/advanced-usage?autoresize=1&fontsize=11&hidenavigation=1&theme=light&view=preview"
style="width:100%; height:500px; border:0; border-radius: 4px; overflow:hidden;"
title="handsontable/hyperformula-demos: advanced-usage"
allow="accelerometer; ambient-light-sensor; camera; encrypted-media; geolocation; gyroscope; hid; microphone; midi; payment; usb; vr; xr-spatial-tracking"
sandbox="allow-autoplay allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts">
</iframe>
24 changes: 23 additions & 1 deletion docs/guide/types-of-values.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ which it's referring. Functions may work differently based on the types of
values.

| Type of value | Description |
| :------------------------- | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|:---------------------------|:-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Number | A numeric value such as 0, 2, -40, 0.1, and also scientific notation e.g. 5.6E+01; with a period as a default decimal separator. |
| Text (string) | A text value, like "ABC", "apollo". |
| Logical (Distinct Boolean) | A logical value might be one of two values: TRUE or FALSE. Please note that even if there is type coercion this will be recognized as TRUE/FALSE when comparing to numbers. It will not be recognized as 1 or 0. |
Expand All @@ -30,6 +30,28 @@ operations such as calculating the number of days between two dates.
- A DateTime value is represented as the number of (possibly fractional) days
since [`nullDate`](../api/interfaces/configparams.md#nulldate).

## Forcing the string value type

Similarly to other popular spreadsheet software, HyperFormula automatically detects the type of an input value.
On some occasions, the value should be treated as a string even though it's parsable as a formula, number, date, time, datetime, boolean, currency or percentage.
Typical examples are numeric values with no number semantics, such as zip codes, bank sort codes, social security numbers, etc.
To prevent the automatic type conversion, you can prepend the string value with an apostrophe character (`'`).

```js
const hf = HyperFormula.buildFromArray([
["11201"], // a number: 11201
["'11201"], // a string: "11201"
["22/06/2022"], // a date: June 22nd 2022
["'22/06/2022"], // a string: "22/06/2022"
]);

// a formula: SUM(B1,B2)
hf.setCellContents({ col: 0, row: 4, sheet: 0 }, [["=SUM(B1,B2)"]]);

// a string: "=SUM(B1,B2)"
hf.setCellContents({ col: 0, row: 5, sheet: 0 }, [["'=SUM(B1,B2)"]]);
```

## Getting cell type

Cells have types that can be retrieved by using the `getCellType` method. Cell
Expand Down
2 changes: 1 addition & 1 deletion test/interpreter/function-randbetween.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe('Interpreter - function RANDBETWEEN', () => {
arr[val] += 1
}
for (const val of arr) {
expect(val).toBeGreaterThan(0)
expect(val).toBeGreaterThan(0) // 10*9^100/10^100 ~= 0.0003 chance of failure if truly random
}
})

Expand Down
Loading