I recently did a bath vanity which was very close to 40". I made a cabinet, then put a tile top on it. I used 36" of 3" tile, then two 2" strips of glass accent tile to get me to the 40".
You can feel free to make the cabinet a bit small, maybe 1/4", and make the facing the exact size, then take a 1/16th at a time off it to get it in tight.
I used urethane grout and I grouted against the tiled wall, but you can use sanded caulk if you prefer.