TEXT function
PRO
The TEXT
function in Jspreadsheet Formulas Pro is a handy tool that lets you change a value into a text according to a specific number format you choose. This means you can alter the way numbers are displayed without changing the actual data. For example, you could use this function to display a number as a date, time, or currency. It's a beneficial feature for improving data readability and presentation.
Documentation
Converts a value to text in a specified number format.
Category
Text
Syntax
TEXT(value, format_text)
Parameter | Description |
---|---|
value |
The value to convert to text. |
format_text |
The number format to apply to the converted text value. |
Behavior
The TEXT
function is used for converting a numeric value into a text string in a specific number format. This function takes two arguments: a value, and a format text. Here's how it handles different types of values:
- Numbers: The
TEXT
function is primarily designed to handle numeric values. It converts them into text according to the specified format. - Text: If you pass a text value as the first argument, the function might return an error since it expects a numeric value. However, if the text can be interpreted as a number (like "10" or "3.14"), the function will convert it.
- Booleans: If you pass a boolean value (
TRUE
orFALSE
), theTEXT
function will treatTRUE
as 1 andFALSE
as 0, then convert them into text. - Empty cells: If you reference an empty cell, the
TEXT
function will treat it as zero. - Errors: If you reference a cell with an error value, the
TEXT
function will propagate that error.
Common Errors
Error | Description |
---|---|
#VALUE! |
This error usually occurs when the value argument is not a valid numeric value. For example, if the value is a text that cannot be interpreted as a number, you'll get this error. |
Best practices
- Always ensure the value argument is a valid numeric value or a cell reference that contains a valid numeric value. Avoid plain text unless it can be interpreted as a number.
- Be careful when formatting dates and times. Jspreadsheet supports custom formatting strings similar to Excel-style patterns. For example, 'mm' can represent minutes, while 'MM' can represent months.
- Use predefined number formats whenever possible to avoid confusion and errors. Custom number formats can be powerful, but they can also be complex and error-prone.
- Remember that the
TEXT
function converts numbers to text, which might affect subsequent calculations. Use this function wisely and only when necessary.
Usage
A few examples using the TEXT function.
TEXT(1234.5678, "$#,##0.00") returns "$1,234.57"
TEXT(0.75, "0%") returns "75%"
TEXT("Hello", "00000") returns "Hello"
TEXT(44561, "MM/DD/YYYY") returns "12/31/2021"
TEXT(0.625, "hh:mm AM/PM") returns "03:00 PM"
Interactive Spreadsheet Demo
<html>
<script src="https://jspreadsheet.com/v11/jspreadsheet.js"></script>
<script src="https://jsuites.net/v5/jsuites.js"></script>
<link rel="stylesheet" href="https://jsuites.net/v5/jsuites.css" type="text/css" />
<link rel="stylesheet" href="https://jspreadsheet.com/v11/jspreadsheet.css" type="text/css" />
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Material+Icons" />
<script src="https://cdn.jsdelivr.net/npm/@jspreadsheet/formula-pro/dist/index.min.js"></script>
<div id="spreadsheet"></div>
<script>
// Set your JSS license key (The following key only works for one day)
jspreadsheet.setLicense('YmYxZWMyNDUyNzE0MmE3Y2YxNWIyZmVkMzc0ZjA5OTgzMjVkMmQ1OWExNTVkOWI0NzE2YmEyYWQyOTk4YjlhZTA3YWMyNDlmM2U5MmM0MjYwNmEyYjg1Njk1ZGVmNjFkZjRjNTU0NzkzZjg2MzJkZGM2MjYwOWU5YjQ3YTkwOTksZXlKamJHbGxiblJKWkNJNklpSXNJbTVoYldVaU9pSktjM0J5WldGa2MyaGxaWFFpTENKa1lYUmxJam94TnpVM01EY3pOVGcwTENKa2IyMWhhVzRpT2xzaWFuTndjbVZoWkhOb1pXVjBMbU52YlNJc0ltTnZaR1Z6WVc1a1ltOTRMbWx2SWl3aWFuTm9aV3hzTG01bGRDSXNJbU56WWk1aGNIQWlMQ0p6ZEdGamEySnNhWFI2TG1sdklpd2lkMlZpWTI5dWRHRnBibVZ5TG1sdklpd2lkMlZpSWl3aWJHOWpZV3hvYjNOMElsMHNJbkJzWVc0aU9pSXpOQ0lzSW5OamIzQmxJanBiSW5ZM0lpd2lkamdpTENKMk9TSXNJbll4TUNJc0luWXhNU0lzSW1Ob1lYSjBjeUlzSW1admNtMXpJaXdpWm05eWJYVnNZU0lzSW5CaGNuTmxjaUlzSW5KbGJtUmxjaUlzSW1OdmJXMWxiblJ6SWl3aWFXMXdiM0owWlhJaUxDSmlZWElpTENKMllXeHBaR0YwYVc5dWN5SXNJbk5sWVhKamFDSXNJbkJ5YVc1MElpd2ljMmhsWlhSeklpd2lZMnhwWlc1MElpd2ljMlZ5ZG1WeUlpd2ljMmhoY0dWeklpd2labTl5YldGMElsMHNJbVJsYlc4aU9uUnlkV1Y5');
// Set the extensions
jspreadsheet.setExtensions({ formula });
// Create a new spreadsheet
jspreadsheet(document.getElementById('spreadsheet'), {
worksheets: [{
data: [
[
"Sales Amount",
"Formatted Display"
],
[
1234.5678,
"=TEXT(A2,\"$#,##0.00\")"
],
[
0.75,
"=TEXT(A3,\"0%\")"
],
[
42,
"=TEXT(A4,\"000\")"
],
[
1500000,
"=TEXT(A5,\"#,##0\")"
]
]
}]
});
</script>
</html>
import React, { useRef } from "react";
import { Spreadsheet, Worksheet, jspreadsheet } from "@jspreadsheet/react";
import formula from "@jspreadsheet/formula-pro";
import "jsuites/dist/jsuites.css";
import "jspreadsheet/dist/jspreadsheet.css";
// Set license
jspreadsheet.setLicense('YmYxZWMyNDUyNzE0MmE3Y2YxNWIyZmVkMzc0ZjA5OTgzMjVkMmQ1OWExNTVkOWI0NzE2YmEyYWQyOTk4YjlhZTA3YWMyNDlmM2U5MmM0MjYwNmEyYjg1Njk1ZGVmNjFkZjRjNTU0NzkzZjg2MzJkZGM2MjYwOWU5YjQ3YTkwOTksZXlKamJHbGxiblJKWkNJNklpSXNJbTVoYldVaU9pSktjM0J5WldGa2MyaGxaWFFpTENKa1lYUmxJam94TnpVM01EY3pOVGcwTENKa2IyMWhhVzRpT2xzaWFuTndjbVZoWkhOb1pXVjBMbU52YlNJc0ltTnZaR1Z6WVc1a1ltOTRMbWx2SWl3aWFuTm9aV3hzTG01bGRDSXNJbU56WWk1aGNIQWlMQ0p6ZEdGamEySnNhWFI2TG1sdklpd2lkMlZpWTI5dWRHRnBibVZ5TG1sdklpd2lkMlZpSWl3aWJHOWpZV3hvYjNOMElsMHNJbkJzWVc0aU9pSXpOQ0lzSW5OamIzQmxJanBiSW5ZM0lpd2lkamdpTENKMk9TSXNJbll4TUNJc0luWXhNU0lzSW1Ob1lYSjBjeUlzSW1admNtMXpJaXdpWm05eWJYVnNZU0lzSW5CaGNuTmxjaUlzSW5KbGJtUmxjaUlzSW1OdmJXMWxiblJ6SWl3aWFXMXdiM0owWlhJaUxDSmlZWElpTENKMllXeHBaR0YwYVc5dWN5SXNJbk5sWVhKamFDSXNJbkJ5YVc1MElpd2ljMmhsWlhSeklpd2lZMnhwWlc1MElpd2ljMlZ5ZG1WeUlpd2ljMmhoY0dWeklpd2labTl5YldGMElsMHNJbVJsYlc4aU9uUnlkV1Y5');
// Set the extensions
jspreadsheet.setExtensions({ formula });
export default function App() {
// Spreadsheet array of worksheets
const spreadsheet = useRef();
// Worksheet data
const data = [
[
"Sales Amount",
"Formatted Display"
],
[
1234.5678,
"=TEXT(A2,\"$#,##0.00\")"
],
[
0.75,
"=TEXT(A3,\"0%\")"
],
[
42,
"=TEXT(A4,\"000\")"
],
[
1500000,
"=TEXT(A5,\"#,##0\")"
]
];
// Render component
return (
<Spreadsheet ref={spreadsheet}>
<Worksheet data={data} />
</Spreadsheet>
);
}
<template>
<Spreadsheet ref="spreadsheet">
<Worksheet :data="data" />
</Spreadsheet>
</template>
<script>
import { Spreadsheet, Worksheet, jspreadsheet } from "@jspreadsheet/vue";
import "jsuites/dist/jsuites.css";
import "jspreadsheet/dist/jspreadsheet.css";
import formula from "@jspreadsheet/formula-pro";
// Set license
jspreadsheet.setLicense('YmYxZWMyNDUyNzE0MmE3Y2YxNWIyZmVkMzc0ZjA5OTgzMjVkMmQ1OWExNTVkOWI0NzE2YmEyYWQyOTk4YjlhZTA3YWMyNDlmM2U5MmM0MjYwNmEyYjg1Njk1ZGVmNjFkZjRjNTU0NzkzZjg2MzJkZGM2MjYwOWU5YjQ3YTkwOTksZXlKamJHbGxiblJKWkNJNklpSXNJbTVoYldVaU9pSktjM0J5WldGa2MyaGxaWFFpTENKa1lYUmxJam94TnpVM01EY3pOVGcwTENKa2IyMWhhVzRpT2xzaWFuTndjbVZoWkhOb1pXVjBMbU52YlNJc0ltTnZaR1Z6WVc1a1ltOTRMbWx2SWl3aWFuTm9aV3hzTG01bGRDSXNJbU56WWk1aGNIQWlMQ0p6ZEdGamEySnNhWFI2TG1sdklpd2lkMlZpWTI5dWRHRnBibVZ5TG1sdklpd2lkMlZpSWl3aWJHOWpZV3hvYjNOMElsMHNJbkJzWVc0aU9pSXpOQ0lzSW5OamIzQmxJanBiSW5ZM0lpd2lkamdpTENKMk9TSXNJbll4TUNJc0luWXhNU0lzSW1Ob1lYSjBjeUlzSW1admNtMXpJaXdpWm05eWJYVnNZU0lzSW5CaGNuTmxjaUlzSW5KbGJtUmxjaUlzSW1OdmJXMWxiblJ6SWl3aWFXMXdiM0owWlhJaUxDSmlZWElpTENKMllXeHBaR0YwYVc5dWN5SXNJbk5sWVhKamFDSXNJbkJ5YVc1MElpd2ljMmhsWlhSeklpd2lZMnhwWlc1MElpd2ljMlZ5ZG1WeUlpd2ljMmhoY0dWeklpd2labTl5YldGMElsMHNJbVJsYlc4aU9uUnlkV1Y5');
// Set the extensions
jspreadsheet.setExtensions({ formula });
export default {
components: {
Spreadsheet,
Worksheet,
},
data() {
// Worksheet data
const data = [
[
"Sales Amount",
"Formatted Display"
],
[
1234.5678,
"=TEXT(A2,\"$#,##0.00\")"
],
[
0.75,
"=TEXT(A3,\"0%\")"
],
[
42,
"=TEXT(A4,\"000\")"
],
[
1500000,
"=TEXT(A5,\"#,##0\")"
]
]
return {
data
};
}
}
</script>
import { Component, ViewChild, ElementRef } from "@angular/core";
import jspreadsheet from "jspreadsheet";
import * as formula from "@jspreadsheet/formula-pro";
// Set your JSS license key (The following key only works for one day)
jspreadsheet.setLicense('YmYxZWMyNDUyNzE0MmE3Y2YxNWIyZmVkMzc0ZjA5OTgzMjVkMmQ1OWExNTVkOWI0NzE2YmEyYWQyOTk4YjlhZTA3YWMyNDlmM2U5MmM0MjYwNmEyYjg1Njk1ZGVmNjFkZjRjNTU0NzkzZjg2MzJkZGM2MjYwOWU5YjQ3YTkwOTksZXlKamJHbGxiblJKWkNJNklpSXNJbTVoYldVaU9pSktjM0J5WldGa2MyaGxaWFFpTENKa1lYUmxJam94TnpVM01EY3pOVGcwTENKa2IyMWhhVzRpT2xzaWFuTndjbVZoWkhOb1pXVjBMbU52YlNJc0ltTnZaR1Z6WVc1a1ltOTRMbWx2SWl3aWFuTm9aV3hzTG01bGRDSXNJbU56WWk1aGNIQWlMQ0p6ZEdGamEySnNhWFI2TG1sdklpd2lkMlZpWTI5dWRHRnBibVZ5TG1sdklpd2lkMlZpSWl3aWJHOWpZV3hvYjNOMElsMHNJbkJzWVc0aU9pSXpOQ0lzSW5OamIzQmxJanBiSW5ZM0lpd2lkamdpTENKMk9TSXNJbll4TUNJc0luWXhNU0lzSW1Ob1lYSjBjeUlzSW1admNtMXpJaXdpWm05eWJYVnNZU0lzSW5CaGNuTmxjaUlzSW5KbGJtUmxjaUlzSW1OdmJXMWxiblJ6SWl3aWFXMXdiM0owWlhJaUxDSmlZWElpTENKMllXeHBaR0YwYVc5dWN5SXNJbk5sWVhKamFDSXNJbkJ5YVc1MElpd2ljMmhsWlhSeklpd2lZMnhwWlc1MElpd2ljMlZ5ZG1WeUlpd2ljMmhoY0dWeklpd2labTl5YldGMElsMHNJbVJsYlc4aU9uUnlkV1Y5');
// Set the extensions
jspreadsheet.setExtensions({ formula });
@Component({
standalone: true,
selector: "app-root",
template: `<div #spreadsheet></div>`
})
export class AppComponent {
@ViewChild("spreadsheet") spreadsheet: ElementRef;
// Worksheets
worksheets: jspreadsheet.worksheetInstance[];
// Create a new data grid
ngAfterViewInit() {
// Create spreadsheet
this.worksheets = jspreadsheet(this.spreadsheet.nativeElement, {
worksheets: [{
data: [
[
"Sales Amount",
"Formatted Display"
],
[
1234.5678,
"=TEXT(A2,\"$#,##0.00\")"
],
[
0.75,
"=TEXT(A3,\"0%\")"
],
[
42,
"=TEXT(A4,\"000\")"
],
[
1500000,
"=TEXT(A5,\"#,##0\")"
]
]
}]
});
}
}