Train tickets how to purchase, internet or at station
You can buy train ticket in advance on Italo website:
Roma Termini ➤ Florence S.M.Novella (Firenze Santa Maria Novella)
P.S. you might want to post this question under the category 'Transportation', maybe with the title 'Train from Rome to Florence'.
You can also book on Trenitalia,
It depends a little bit on your situation. If you purchase a discount ticket on-line, then that ticket can only be used for that train at that time. Miss the train. No refund or exchange. Since there are something like 30 to 40 trains a day to Florence, you do not need to purchase early if concerned about the train being sold out. Just doesn't happen. It is easy to purchase at the station via a live person at a ticket window or use a ticket machine. If arriving on a flight from the US, then you do not want to purchase until your feet are on the ground. Trenitalia.com is the national railroad company and I would start with that web site for tickets.
https://www.seat61.com/train-travel-in-italy.htm#intercity-trains is a wealth of knowledge!