Formatting money with a dollar sign

Post Reply
Azzurosky
Posts: 10
Joined: Mon May 27, 2019 12:46 pm
My devices: iPhone, ipad
Flag: Australia

Formatting money with a dollar sign

Post by Azzurosky »

Is there a way to ensure that the dollar sign is immediately to the left of an amount of money when output?

E.g.

X=12345
PRINT "$#####" : X

Prints $12345, which is fine.

But if X is 345 then it prints $ 345, inserting two spaces after the $ sign.

How can I ensure that the $ sign is immediately to the left of the first digit? In some versions of Basic using $$ solves the problem, but that doesn't appear to work in Smart Basic

User avatar
Mr. Kibernetik
Site Admin
Posts: 4786
Joined: Mon Nov 19, 2012 10:16 pm
My devices: iPhone, iPad, MacBook
Location: Russia
Flag: Russia

Re: Formatting money with a dollar sign

Post by Mr. Kibernetik »

The simplest way is:

Code: Select all

x=345
print "$"&x

Post Reply