hyTags
HomeHome DocumentationDocumentation

number-to-string

Converts a number to a string with optional formatting
Parameter
Type
Description
self
Number
The number to convert to a string
integer-places
Number?
The minimum number of integer digits (pads with zeros if needed)
decimal-places
Number?
The number of decimal places to include in the output
prefix
String?
A string to prepend to the result
suffix
String?
A string to append to the result
return
string
A string representation of the number with optional formatting
Test Case:Convert number to string
    <div></div>
    
    <number-new value="42">
    <number-to-string>
    <assert-equal value="42" type="string">
    
    👆 Try to change something!
  • Test Case:Format with decimal places
      <div></div>
      
      <number-new value="3.14159">
      <number-to-string decimal-places="2">
      <assert-equal value="3.14" type="string">
      
      👆 Try to change something!
    • Test Case:Format with integer padding
        <div></div>
        
        <number-new value="5">
        <number-to-string integer-places="3">
        <assert-equal value="005" type="string">
        
        👆 Try to change something!
      • Test Case:Format with prefix
          <div></div>
          
          <number-new value="100">
          <number-to-string prefix="$">
          <assert-equal value="$100" type="string">
          
          👆 Try to change something!
        • Test Case:Format with suffix
            <div></div>
            
            <number-new value="50">
            <number-to-string suffix="%">
            <assert-equal value="50%" type="string">
            
            👆 Try to change something!
          • Test Case:Format with prefix and suffix
              <div></div>
              
              <number-new value="99.5">
              <number-to-string decimal-places="1" prefix="$" suffix=" USD">
              <assert-equal value="$99.5 USD" type="string">
              
              👆 Try to change something!
            • Test Case:Format with all options
                <div></div>
                
                <number-new value="7">
                <number-to-string integer-places="2" decimal-places="2" prefix="#" suffix="!">
                <assert-equal value="#07.00!" type="string">
                
                👆 Try to change something!
              • Test succeeded Test failed