CircuitGizmos

Electronic Products for Creative Minds

  • Home
  • Gizmo Store/Products
  • Documentation/Datasheets
  • Projects/Libraries
  • GizmoBlog
  • Services/Contact
    • Design
    • Contact Gizmo!
  • Your Gizmo Cart
    • Your Account
You are here: Home / GizmoBlog / MMBasic Language / Character and String Functions / FORMAT$

FORMAT$

FORMAT$( nbr [, fmt$] )

MMbasic 4.5, not 5.0

Will return a string representing ‘nbr’ formatted according to the specifications in the string ‘fmt$’.

The format specification starts with a % character and ends with a letter. Anything outside of this construct is copied to the output as is.

The structure of a format specification is:

% [flags] [width] [.precision] type

Where ‘flags’ can be:

– Left justify the value within a given field width

0 Use 0 for the pad character instead of space

+ Forces the + sign to be shown for positive numbers

space Causes a positive value to display a space for the sign. Negative values still show the – sign

‘width’ is the minimum number of characters to output, less than this the number will be padded, more than this the width will be expanded.

‘precision’ specifies the number of fraction digits to generate with an e, or f type or the maximum number of significant digits to generate with a g type. If specified the precision must be preceded by a dot (.).

‘type’ can be one of:

g Automatically format the number for the best presentation.

f Format the number with the decimal point and following digits

e Format the number in exponential format

If uppercase G or F is used the exponential output will use an uppercase E. If the format specification is not specified “%g” is assumed.


PRINT FORMAT$(45)

45

PRINT FORMAT$(45, "%g")

45

PRINT FORMAT$(24.1, "%g")

24.1

PRINT FORMAT$(24.1, "%f")

24.100000

PRINT FORMAT$(24.1, "%e")

2.410000e+01

PRINT FORMAT$(24.1, "%09.3f")

00024.100

PRINT FORMAT$(24.1, "%+.3f")

+24.100

PRINT FORMAT$(24.1, "**%-9.3f**")

**24.100 **


See also:
INSTR
LCASE
LEFT$
LEN
MID$
RIGHT$
SPACE$
SPC
STRING$
UCASE$

Applies to:

CGCOLORMAX

CGMMSTICK

CGMICROBOARD

CGMICROMITE

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

A Ton of Documentation

Open all | Close all

Projects made by Gizmo, Friends, and Members

open all | close all

Recent GizmoBlog Musings

  • Altair 8800 using a ColorMax!
  • Re-energizing the ColorMax, Pt. 3

Visit us!

  • Facebook

Electronic Products for Creative Minds

CircuitGizmos is your source for electronic products that help you create your embedded projects. Here at CircuitGizmos.com you will find a friendly store filled with creative products and all of the documentation that you need to use these gizmos.

We create devices that we believe make electronics fun, but we also know that our products are used for professional designs. For decades we have designed products for commercial, military, and medical industries. Our gizmos here are great for engineers and hobbyists alike.

Copyright © 2008+ CircuitGizmos, L.L.C. All rights reserved

Image already added

Recently Viewed Products

Copyright © 2025 · Generate Pro Theme on Genesis Framework · WordPress · Log in