Use amount and quantity to replace number?

When we want to express the quantity of something (countable), we may say "The number of something is + number", like "The number of books is 3."

Can I say “The quantity of books is 3”? I mean "The quantity of something is a number". Is that correct?

If the stuff is uncountable, like water, can I say "The amount of water is 3 cubic meters"? So that the pattern becomes "The amount of something is + number + measurement units". Is that the formal usage?

"The number of books is three" or "The quantity of water is three cubic meters" both sound rather convoluted and unnatural to me. Instead I'd suggest you say

There are three books

There are three cubic meters of water

Even when you are asked a question "What is the number of books?" it is much more common to respond "It is three" or "There are three books" or just "Three". There is no need to make a complicated answer!

Yes, you can say "the quantity of books", though it sounds rather formal to my ears.

Quantity = the amount or number of a material or abstract thing not usually estimated by spatial measurement.

I'd say "amount" seems less formal than "quantity", and both work when it comes to countable objects. You can also use "allotment".