@@ -142,6 +142,49 @@ public static function ATAN2($xCoordinate = null, $yCoordinate = null)
142
142
return Functions::VALUE ();
143
143
}
144
144
145
+ /**
146
+ * BASE.
147
+ *
148
+ * Converts a number into a text representation with the given radix (base).
149
+ *
150
+ * Excel Function:
151
+ * BASE(Number, Radix [Min_length])
152
+ *
153
+ * @category Mathematical and Trigonometric Functions
154
+ *
155
+ * @param float $number
156
+ * @param float $radix
157
+ * @param int $minLength
158
+ *
159
+ * @return string the text representation with the given radix (base)
160
+ */
161
+ public static function BASE ($ number , $ radix , $ minLength = null )
162
+ {
163
+ $ number = Functions::flattenSingleValue ($ number );
164
+ $ radix = Functions::flattenSingleValue ($ radix );
165
+ $ minLength = Functions::flattenSingleValue ($ minLength );
166
+
167
+ if (is_numeric ($ number ) && is_numeric ($ radix ) && ($ minLength === null || is_numeric ($ minLength ))) {
168
+ // Truncate to an integer
169
+ $ number = (int ) $ number ;
170
+ $ radix = (int ) $ radix ;
171
+ $ minLength = (int ) $ minLength ;
172
+
173
+ if ($ number < 0 || $ number >= 2 ** 53 || $ radix < 2 || $ radix > 36 ) {
174
+ return Functions::NAN (); // Numeric range constraints
175
+ }
176
+
177
+ $ outcome = strtoupper ((string ) base_convert ($ number , 10 , $ radix ));
178
+ if ($ minLength !== null ) {
179
+ $ outcome = str_pad ($ outcome , $ minLength , '0 ' , STR_PAD_LEFT ); // String padding
180
+ }
181
+
182
+ return $ outcome ;
183
+ }
184
+
185
+ return Functions::VALUE ();
186
+ }
187
+
145
188
/**
146
189
* CEILING.
147
190
*
0 commit comments